如何导致发送的电子邮件在Gmail邮件收件人的视图中显示为带有Message-ID,In-Reply-To和References的线索 [英] How to cause sent emails to appear threaded in GMail recipient's view with Message-ID, In-Reply-To and References

查看:788
本文介绍了如何导致发送的电子邮件在Gmail邮件收件人的视图中显示为带有Message-ID,In-Reply-To和References的线索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些很棒的在线资源,如 http://www.jwz.org/doc /threading.html ,似乎任何电子邮件都会发送一个 Message-ID 标题,那么任何回复都包括 In命名该ID和 Ref。可以命名一个父消息ID列表,电子邮件客户端使用此信息在查看时构造线程电子邮件列表在线程视图。



我的问题是:可以将一系列电子邮件发送给具有伪造标题的收件人,以使其显示在没有收件人回复他们?如果是这样,为什么我以下的尝试不起作用?



我们有一个系统发送与我们系统中特定实体相关的几封电子邮件。让我们说,我们为每个小部件多次销售小部件和电子邮件用户。我们希望所有电子邮件的特定小部件ID在用户的电子邮件客户端中显示为电子邮件线程。



这里的旅程似乎是通常发送电子邮件,然后回复至。我们的系统只是想发送几封电子邮件,并伪造In-Reply-To和引用标题,以欺骗电子邮件客户端将其显示在树中。



-ID格式我使用的是:'foobar'+ widgetId + sequence




  • widgetId =每个小部件唯一的数字例如1234

  • sequence =每次发送电子邮件时递增的序列号



第一封电子邮件:




  • Message-ID < foobar-1234-0@server.com>

  • 回复方式:未提供

  • 参考文献:未提供



第二封电子邮件:




  • Message-ID < foobar-1234-1 @ server .com>

  • In-Reply-To:< foobar-1234-0@server.com>

  • 参考文献:< foobar-1234-0@server.com>



    • 第三封电子邮件:




      • Message-ID < foobar -1234-2@server.com>

      • 回覆者:< foobar-1234-1@server.com> ;

      • 参考文献:< foobar-1234-0@server.com& < foobar-1234-1@server.com>



      (顺便说一句,包括 @ server.com 消息ID的部分似乎至关重要,没有使用例如 foobar-123-0 ,我们的SMTP服务器简单地忽略它,并使用它自己的自动生成的消息ID)



      电子邮件在Thunderbird中正确显示,作为一个树,但不在Gmail中,他们只是一个接一个地列出在收件箱中,而其他会话在他们旁边正确地被线程打到。我不知道如果我错了,Thunderbird正在做最好的数据可能与坏的数据,或如果Gmail需要一些额外的非标准糖我不提供。



      这是我的node.js测试脚本:

        / * jshint dojo:true * / 
      / *全局控制台:true * /
      'use strict';
      var Q = require('q'),
      nconf = require('nconf'),
      optimist = require('optimist'),
      nodemailer = require('nodemailer );

      console.log('开始运行');
      var argv = optimist.argv,
      config = nconf.argv()。env()。file('conf.json'),
      smtpConfig = config.get('smtp') ,
      smtpTransport = nodemailer.createTransport('SMTP',{
      service:smtpConfig.service,//'Gmail',
      auth:{
      user:smtpConfig.user,/ /'blah@gmail.com',
      pass:smtpConfig.pass //'xyz'
      }
      }),
      rand = Math.floor(Math.random() * 5000),//一个随机足够的唯一ID
      messageIdPrefix ='foobar-'+ rand +' - ';

      var promises = [],
      references ='';

      for(var i = 0; i <3; i ++){
      //准备电子邮件内容
      var subject ='这是测试电子邮件'+ i,
      htmlMessage ='< h1&我的线程?电子邮件'+ i +'< / h1>< p> ???< / p>',
      textMessage ='我是线程?电子邮件'+ i +'\\\
      \\\
      ???';

      var recipients ='recipient@server.com';

      //此序列中的每个电子邮件都有一个共同的前缀
      //在回复中应该是单个直接的父消息id
      //引用应列出所有父母,最多第一个
      var messageId = messageIdPrefix + i +'@ server.com',
      inReplyTo =(i> 0)? ('<'+(messageIdPrefix +(i-1))+'@ server.com>'):false;

      //使用unicode符号设置电子邮件数据
      var mailOptions = {
      from:config.get('ourEmail'),
      to:recipients,
      主题:主题,
      文本:textMessage,
      html:htmlMessage,
      messageId:messageId,
      inReplyTo:inReplyTo,
      引用:引用,
      标题:{
      //'in-Reply-To':inReplyTo
      }
      };

      //使用定义的传输对象发送邮件
      var q = Q.defer();
      promises.push(q.promise);
      smtpTransport.sendMail(mailOptions,function(error,response){
      if(error){
      console.error(error);
      q.reject('error');
      } else {
      console.log('Message sent:'+ response.message);
      q.resolve('yay!');
      }
      } );

      //下一次循环循环(如果有的话)在引用列表中包含此id
      references =(references?(references +''):'')+ messageId;
      }

      Q.all(promises).then(function(results){
      console.log('All done,closing mail connection:',results);
      smtpTransport.close(); //关闭连接池,不再有消息
      });

      需要一个conf文件,如:



      <$ p

      我们的邮箱:me@server.com,
      smtp:{
      service:Gmail,
      user:me@server.com,
      pass:ilikecheese
      }
      }

      对于积分,请提示为什么我尝试使用 Q.all 似乎没有触发,脚本不正确地退出,尽管发送所有电子邮件正确:)

      解决方案

      解决方案为什么他们没有在Gmail中线程是因为Gmail的线程根据消息的主题完成(它不是基于标题中的回复到或引用字段)。



      请参阅有关Gmail的线程的详细信息,请参阅stackexchange上的这个问题的答案: https://webapps.stackexchange.com/questions/965 / how-do-gmail-decision-to-thread-email-messages ..



      您的案例中的主题是这是测试电子邮件1 ,这是测试电子邮件2和这是测试电子邮件3,这不会导致Gmail使用规则的线程。


      I've read some great online resources like http://www.jwz.org/doc/threading.html, and it seems that any email is send with a Message-ID header, then any replies to it include In-Reply-To naming that ID and Refences which can name a list of parent message id's, and email clients use this information to construct threads when viewing a list of emails in threaded view.

      My question is: Can a series of emails be sent to a recipient with faked headers, to make them appear in a thread without the recipient replying to them? If so, why does my attempt below not work?

      We have a system that sends out several emails pertaining to a specific entity in our system. Lets say we sell widgets and email users several times about each widget. We want all emails for a specific widget ID to appear as an email thread in our user's email clients.

      The trip here seems to be that normally emails are sent, then replied to. Our system simply wants to send out several emails, and fake the In-Reply-To and References headers, to trick email clients into displaying them in a tree.

      The Message-ID format I'm using is: 'foobar' + widgetId + sequence

      • widgetId = a number unique to each widget e.g. 1234
      • sequence = a sequential number incremented each time we send an email

      First email:

      • Message-ID <foobar-1234-0@server.com>
      • In-Reply-To: not provided
      • References: not provided

      Second email:

      • Message-ID <foobar-1234-1@server.com>
      • In-Reply-To: <foobar-1234-0@server.com>
      • References: <foobar-1234-0@server.com>

      Third email:

      • Message-ID <foobar-1234-2@server.com>
      • In-Reply-To: <foobar-1234-1@server.com>
      • References: <foobar-1234-0@server.com> <foobar-1234-1@server.com>

      (incidentally, including the @server.com portion of a message ID appears to be vital. Without that, using e.g. foobar-123-0, our SMTP server simply ignored it and used it own autogenerated message ID)

      Emails appear correctly in Thunderbird, as a tree, but not in Gmail, they just get listed one after the other in the Inbox while other conversations are properly threaded right next to them. I'm not sure if I'm getting it wrong and Thunderbird is doing the best it can with bad data, or if Gmail needs some extra nonstandard sugar I'm not providing.

      Here is my node.js test script:

      /*jshint dojo:true */
      /*global console:true */
      'use strict';
      var Q = require('q'),
          nconf = require('nconf'),
          optimist = require('optimist'),
          nodemailer = require('nodemailer');
      
      console.log('Started to run.');
      var argv = optimist.argv,
          config = nconf.argv().env().file('conf.json'),
          smtpConfig = config.get('smtp'),
              smtpTransport = nodemailer.createTransport('SMTP', {
                  service: smtpConfig.service, // 'Gmail',
                  auth: {
                      user: smtpConfig.user, //'blah@gmail.com',
                      pass: smtpConfig.pass //'xyz'
                  }
              }),
          rand = Math.floor(Math.random() * 5000), // a random enough unique id
          messageIdPrefix = 'foobar-' + rand + '-';
      
      var promises = [],
          references = '';
      
      for (var i = 0 ; i < 3 ; i ++) {
          // Prepare email content
          var subject = 'This is test email ' + i,
              htmlMessage = '<h1>Am I threaded? Email ' + i + '</h1><p>???</p>',
              textMessage = 'Am I threaded? Email ' + i + '\n\n???';
      
          var recipients = 'recipient@server.com';
      
          // Each email in this sequence has a common prefix
          // In Reply To should be the single immediate parent message id
          // References should list all parents, top most first
          var messageId = messageIdPrefix + i + '@server.com',
              inReplyTo = (i > 0) ? ('<' + (messageIdPrefix + (i-1)) + '@server.com>') : false;
      
          // setup e-mail data with unicode symbols
          var mailOptions = {
              from: config.get('ourEmail'),
              to: recipients,
              subject: subject,
              text: textMessage,
              html: htmlMessage,
              messageId: messageId,
              inReplyTo: inReplyTo,
              references: references,
              headers: {
                  // 'in-Reply-To': inReplyTo
              }
          };
      
          // send mail with defined transport object
          var q = Q.defer();
          promises.push(q.promise);
          smtpTransport.sendMail(mailOptions, function (error, response) {
              if (error) {
                  console.error(error);
                  q.reject('error');
              } else {
                  console.log('Message sent: ' + response.message);
                  q.resolve('yay!');
              }
          });
      
          // next time round loop, if any, includes this id in the references list
          references = (references ? (references + ' ') : '') + messageId;
      }
      
      Q.all(promises).then(function (results) {
          console.log('All done, closing mail connection: ', results);
          smtpTransport.close(); // shut down the connection pool, no more messages
      });
      

      Requires a conf file like:

      {
          "ourEmail": "me@server.com",
          "smtp": {
              "service": "Gmail",
              "user": "me@server.com",
              "pass": "ilikecheese"
          }
      }
      

      For bonus points, please hint why my attempt to use Q.all doesn't seem to fire and the script does not exit cleanly, despite sending all emails correctly :)

      解决方案

      The answer to why they are not threaded in Gmail is because Gmail's threading is done according to the subject of the messages (it is not based on the "in-reply-to" or "references" field in the header).

      See the answers to this question on stackexchange for more details on how Gmail does threading: https://webapps.stackexchange.com/questions/965/how-does-gmail-decide-to-thread-email-messages..

      The subjects in your case are "This is test email 1", "This is test email 2" and "This is test email 3" which will not cause threading by the rules Gmail use.

      这篇关于如何导致发送的电子邮件在Gmail邮件收件人的视图中显示为带有Message-ID,In-Reply-To和References的线索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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