1

I recently came to know about AMP email and found it interesting and tried an example in nodejs using nodemailer package.

This package already contains an option 'amp' to send AMP specific emails, however I am unable to make it work.

The AMP version of email is really plain and it doesnt contain any xhr requests. Below is my code which sends an email to a specific email address.

  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);
  });

Also, I tried using "MailKit" package in C# but was not sure how to set an AMP version here. I added my AMP version under message.body section of MimeMessage class.

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

I am sure there is something really small that I am missing but unable to figure it out. Could someone take a look and guide me whats going wrong with above code?

4

1 回答 1

2

AMP 不是 RichText,它是带有特殊 Content-Type 的 HTML,旨在成为multipart/alternative.

我建议阅读https://amp.dev/documentation/guides-and-tutorials/learn/amp-email-format

要在 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;

希望有帮助。

于 2019-05-07T18:10:58.210 回答