Are you that programmer that knows all about emails? Can you dream about mail headers, write them with your eyes closed? Maybe you might be able to help me with this issue.
Let me explain ...
Inbox
in my applicationIn that same application a user can send new emails. I've handled that using the following code snippet.
$message = \Swift_Message::newInstance()
->setSubject($form->get('subject')->getData())
->setFrom('[email protected]')
->setTo($form->get('to'))
->setBody(
$this->renderView(
'MailBundle:Email:contact.html.twig',
array(
'ip' => $request->getClientIp(),
'name' => $form->get('to')->getData(),
'message' => $form->get('message')->getData()
)
)
)
;
This works fine. If the above email is submitted I create a new email in the IMAP sent folder. This, on his turn is being imported by the PHP cronjob and put in the MySQL database. It shows up in the sent folder in my application.
Now that you have a general idea of how my application works I've got some things I am not so sure about.
I would like to use my application as a real mailclient and want the mail headers etc. to be correctly set.
I could of course just send an email with the original mail body and the subject prepended with "RE:". But I am not sure if that's all. I somehow suspect I need to do alot more.
How would I use SwiftMailer to reply to or forward an email that is saved in a database?
I implemented the reply headers as suggested in an answer to this question. I'm not sure however if this will work for the forwarding as well. I just wanna make sure that mail providers won't block my emails because the headers are incorrect.
I compared what are the differences in the header between a "first" email and a reply.
To make a reply, it seems you've to add two lines in the reply header :
In-Reply-To: [Message-ID] (with Message-ID found in the header of the first mail)
References: [Message-ID]
Obviously, you have to change the from
and to
in the reply email. (I think SwiftMailer creates others by itself)
To add line in email header using SwiftMailer, proceed like that :
$headers = $message->getHeaders();
$headers->addTextHeader('In-Reply-To', $previousEmail->getHeaders()->getMessageId());
This getter I put is just how I imagine your email entity.
For the forward, juste print the source of an email and check differences.
Hope it could help.
Update :
For a forward : it is exactly the same thing. I just compared the two headers.
You've to add In-Reply-To
and References
.
And to answer your update : You can put anything you want (string obviously) in an email header. The spam score will not grow up if you add an unknown variable in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With