正确的标题用于回复和转发电子邮件 [英] Correct headers for replying and forwarding emails

查看:722
本文介绍了正确的标题用于回复和转发电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你是那位知道电子邮件的程序员吗?你可以梦想着邮件头,用你的眼睛闭上吗?也许你可能可以帮助我解决这个问题。



让我解释一下...



工作流程




  • 邮件服务器收到电子邮件

  • PHP cronjob将IMAP中的所有电子邮件导入MySQL数据库

  • 用户在我的应用程序


中的收件箱中查找所有电子邮件

发送电子邮件



在同一个应用程序中,用户可以发送新的电子邮件。我已经处理了使用以下代码片段。

  $ message = \Swift_Message :: newInstance()
- > setSubject($ form-> get('subject') - > getData())
- > setFrom('me@example.com')
- > setTo($ form-> get('to'))
- > setBody(
$ this-> renderView(
'MailBundle:Email:contact.html.twig',
数组(
'ip'=> $ request-> getClientIp(),
'name'=> $ form-> get('to') - > getData()
'message'=> $ form-> get('message') - > getData()



;

这工作正常。如果提交上述电子邮件,我将在IMAP发送的文件夹中创建一个新的电子邮件。这个转而由PHP cronjob导入并放入MySQL数据库。



问题



现在你有一个一般的想法我的应用程序的工作原理我有一些我不太清楚的事情。




  • 如何使用SwiftMailer创建对导入的电子邮件的回复。

  • 如何使用SwiftMailer转发导入的电子邮件



我想使用我的应用程序作为一个真正的邮件客户端,并希望邮件头等被正确设置。



我当然可以发送一封包含原始邮件正文的电子邮件,回覆:。但我不知道是否这样。我不知何故怀疑我需要做更多的事情。



简而言之



我如何使用SwiftMailer来回复或转发保存在数据库中的电子邮件?



更新



我按照建议这个问题的答案。我不知道这是否也适用于转发。我只是想确保邮件提供商不会阻止我的电子邮件,因为标题不正确。

解决方案

我比较了在第一个电子邮件和回复之间的标题差异。



要作出回复,您似乎必须在回复标题中添加两行: p>


  • In-Reply-To:[Message-ID](在第一封邮件的标题中找到Message-ID) p>


  • 参考文献:[Message-ID]




显然,你必须将更改到回复电子邮件中的。 (我认为SwiftMailer自己创建别人)



要使用SwiftMailer在电子邮件头中添加行,请按以下步骤操作:

  $ headers = $ message-> getHeaders(); 

$ headers-> addTextHeader('In-Reply-To',$ previousEmail-> getHeaders() - > getMessageId());

这个getter是我想象的电子邮件实体。



对于前进,juste打印电子邮件的来源并检查差异。



希望可以帮助。






更新:



对于前锋:这是完全一样的事情。我只是比较了两个标题。



你必须添加 In-Reply-To 参考



并回答您的更新:您可以将任何您想要的(字符串显式)放在电子邮件标题中。如果您在其中添加未知变量,则垃圾邮件分数不会增长。


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 ...

Workflow

  • The mail server receives emails
  • A PHP cronjob imports all emails from IMAP into the MySQL database
  • The user finds all emails in the Inbox in my application

Sending an email

In 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('me@example.com')
    ->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.

The issue

Now that you have a general idea of how my application works I've got some things I am not so sure about.

  • How can I create replies to imported emails using SwiftMailer.
  • How can I forward imported emails using SwiftMailer

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.

In short

How would I use SwiftMailer to reply to or forward an email that is saved in a database?

Update

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.

这篇关于正确的标题用于回复和转发电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆