Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用NodeEmailer发送AMP电子邮件_Node.js_C# 4.0_Nodemailer_Mailkit_Amp Email - Fatal编程技术网

Node.js 使用NodeEmailer发送AMP电子邮件

Node.js 使用NodeEmailer发送AMP电子邮件,node.js,c#-4.0,nodemailer,mailkit,amp-email,Node.js,C# 4.0,Nodemailer,Mailkit,Amp Email,我最近开始了解AMP电子邮件,发现它很有趣,并尝试了使用nodemailer包在nodejs中的一个示例 这个软件包已经包含了一个选项“amp”来发送特定于amp的电子邮件,但是我无法让它工作 AMP版本的电子邮件非常简单,不包含任何xhr请求。 下面是我向特定电子邮件地址发送电子邮件的代码 let transporter = nodeMailer.createTransport({ host: 'smtp.gmail.com', port: 465, secure:

我最近开始了解AMP电子邮件,发现它很有趣,并尝试了使用nodemailer包在nodejs中的一个示例

这个软件包已经包含了一个选项“amp”来发送特定于amp的电子邮件,但是我无法让它工作

AMP版本的电子邮件非常简单,不包含任何xhr请求。 下面是我向特定电子邮件地址发送电子邮件的代码

  let transporter = nodeMailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
      user: "validuser@gsuiteBusinessdomain.com",
      pass: "validpassword"
  },
  });

  let mailOptions = {
    from: 'sender@gsuiteBusinessdomain.com', // sender address
    to: "enduser@gsuiteBusinessdomain.com", // list of receivers
    subject: "test subject", // Subject line
    text: " basic text body example ", // plain text body
    html: '<b>basic html body example</b>', // html body
    amp: `<!--
        Below is the mininum valid AMP4EMAIL document. Just type away
        here and the AMP Validator will re-check your document on the fly.
   -->
   <!doctype html>
   <html ⚡4email>
   <head>
     <meta charset="utf-8">
     <script async src="https://cdn.ampproject.org/v0.js"></script>
     <style amp4email-boilerplate>body{visibility:hidden}</style>
   </head>
   <body>
     Hello, AMP4EMAIL world.
   </body>
   </html>`
  };

  transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
      console.log(error);
    }
    console.log('Message %s sent: %s', info.messageId, info.response);
  });
let transporter=nodeEmailer.createTransport({
主机:“smtp.gmail.com”,
港口:465,
安全:是的,
认证:{
用户:“validuser@gsuiteBusinessdomain.com",
通行证:“有效密码”
},
});
让邮件选项={
发件人:'sender@gsuiteBusinessdomain.com“,//发件人地址
至:enduser@gsuiteBusinessdomain.com“,//接收者列表
主题:“测试主题”,//主题行
text:“基本文本正文示例”,//纯文本正文
html:'基本html正文示例',//html正文
放大器:`
正文{可见性:隐藏}
你好,AMP4电子邮件世界。
`
};
transporter.sendMail(邮件选项,(错误,信息)=>{
如果(错误){
console.log(错误);
}
console.log('发送的消息%s:%s',info.messageId,info.response);
});
此外,我尝试在C#中使用“MailKit”包,但不确定如何在这里设置AMP版本。我在message.body部分添加了我的AMP版本 MimeMessage类的

 message.Body = new TextPart(TextFormat.RichText)
            {
                Text = @"<!-- ........
message.Body=newtextpart(TextFormat.RichText)
{

Text=@“AMP不是RichText,它是一种具有特殊内容类型的HTML,它是
多部分/备选方案的一部分

我建议你读书

要在MimeKit/MailKit中发送AMP,请执行以下操作:

var alternative = new MultipartAlternative ();
alternative.Add (new TextPart ("plain") {
    Text = "This is the plain-text message body."
});

// Note: Some email clients[1] will only render the last MIME part, so we
// recommend placing the text/x-amp-html MIME part before the text/html
// MIME part.
alternative.Add (new TextPart ("x-amp-html") {
    Text = @"<!--
    Below is the minimum valid AMP4EMAIL document. Just type away
    here and the AMP Validator will re-check your document on the fly.
-->
<!doctype html>
<html ⚡4email>
<head>
  <meta charset=""utf-8"">
  <script async src=""https://cdn.ampproject.org/v0.js""></script>
  <style amp4email-boilerplate>body{visibility:hidden}</style>
</head>
<body>
  Hello, AMP4EMAIL world.
</body>
</html>"
});

alternative.Add (new TextPart ("html") {
    Text = "This is the <b>html</b> message body."
});

message.Body = alternative;
var alternative=newmultipartalternative();
备选方案。添加(新文本部分(“普通”){
Text=“这是纯文本消息正文。”
});
//注意:一些电子邮件客户端[1]只会呈现最后一个MIME部分,因此我们
//建议将text/x-amp-html MIME部分放在text/html之前
//哑剧角色。
可选。添加(新文本部分(“x-amp-html”){
Text=@”
正文{可见性:隐藏}
你好,AMP4电子邮件世界。
"
});
可选。添加(新文本部分(“html”){
Text=“这是html消息正文。”
});
message.Body=备选方案;

希望这能有所帮助。

谢谢@jstedfast的回复。我以前应该提到过。我甚至使用了HTML格式,但这并没有给我一个AMP页面,而只是一个HTML页面。我想你(或者我?)对AMP电子邮件的确切含义感到困惑。根据你设置邮件正文的文本,这就是HTML。所以当你告诉我“是的,但它显示为HTML“我想”嗯,嗯,因为它是。你为什么期待一些不同的东西?没关系,我看到了问题,你需要一个特殊的mime类型。我会更新我的答案。是的,这正是我想要的。谢谢你指导我找到正确的道路