为什么编码 headers 内容类型:text/html;在 Outlook 插件中使用 MailItem 时缺少 GMAIL 的 SMTP 服务器:SMTP.GMAIL.COM?
Why encoding headers content type: text/html; is missing when use MailItem in Outlook plugin, whith the SMTP server of GMAIL: SMTP.GMAIL.COM?
我尝试将 HTML 发送到 gmail 帐户,从 gmail SMTP 服务器发送。
如果我这样写代码并发送 HTML 就没有问题。
MailMessage mail = new MailMessage("aaaa@gmail.com", to, subject, body);
mail.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient(smtp);
smtpClient.EnableSsl = true;
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential(userName, password);
smtpClient.Send(mail);
gmail账户收到的邮件是base64的
随着 headers :
Subject: Test
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
PGh0bWw==
(这个base 64无效,仅作题用)
但是,如果我使用 Outlook.MailItem 发送我的电子邮件,我就会得到......
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<https://fdsafasdfasd.com/images/logo.png> =09
Cedric Boivin
cboivin@fadsfdasfads.com
Vous a envoy=E9 un message s=E9curis=E9 vifdasfasdfes
我的文字看起来很清晰,而不是在 Gmail 中 HTML。 Outlook 插件中有我的代码
Microsoft.Office.Interop.Outlook.MailItem newMail = Globals.ThisAddIn.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
// newMail.Display(false);
newMail.Subject = subject;
newMail.To = email.ToLower().Trim();
newMail.Recipients.ResolveAll();
newMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
newMail.HTMLBody = htmlBody;
newMail.Send();
有什么建议吗?
我测试了您的 Outlook 邮件代码发送邮件,我可以在我的 gmail 帐户中正确看到 HTML 格式的邮件。我的环境是:VS 2015 / Outlook 2016
有趣的是,在我的测试中我看到了 - Content-Type: text/plain;
和 Content-Type: text/html;
。代码只是单独设置 HtmlBody
。
发送邮件后,如果您在 Outlook 中查看 "Sent items" - 邮件的格式是什么?
可能是您的 Outlook 设置中的某些东西正在将其转换为纯文本!在旧版本的 Outlook 中,有一个选项 convert to Plain text for specific users。您是否正在使用这些版本中的任何一个并打开此选项?
在我的测试中,只有当我设置 .Body
而不是 .HtmlBody
时,我才会得到你的行为,即 newMail.Body = htmlBody;
我发现了问题。
在我发送的电子邮件中,我为 mailItem 设置了一些属性。
这与这篇文章有关...
Prevent winmail.dat in outlook (for gmail accounts)
如果我删除它们...一切正常。
我尝试将 HTML 发送到 gmail 帐户,从 gmail SMTP 服务器发送。
如果我这样写代码并发送 HTML 就没有问题。
MailMessage mail = new MailMessage("aaaa@gmail.com", to, subject, body);
mail.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient(smtp);
smtpClient.EnableSsl = true;
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential(userName, password);
smtpClient.Send(mail);
gmail账户收到的邮件是base64的 随着 headers :
Subject: Test
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
PGh0bWw==
(这个base 64无效,仅作题用)
但是,如果我使用 Outlook.MailItem 发送我的电子邮件,我就会得到......
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<https://fdsafasdfasd.com/images/logo.png> =09
Cedric Boivin
cboivin@fadsfdasfads.com
Vous a envoy=E9 un message s=E9curis=E9 vifdasfasdfes
我的文字看起来很清晰,而不是在 Gmail 中 HTML。 Outlook 插件中有我的代码
Microsoft.Office.Interop.Outlook.MailItem newMail = Globals.ThisAddIn.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
// newMail.Display(false);
newMail.Subject = subject;
newMail.To = email.ToLower().Trim();
newMail.Recipients.ResolveAll();
newMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
newMail.HTMLBody = htmlBody;
newMail.Send();
有什么建议吗?
我测试了您的 Outlook 邮件代码发送邮件,我可以在我的 gmail 帐户中正确看到 HTML 格式的邮件。我的环境是:VS 2015 / Outlook 2016
有趣的是,在我的测试中我看到了 - Content-Type: text/plain;
和 Content-Type: text/html;
。代码只是单独设置 HtmlBody
。
发送邮件后,如果您在 Outlook 中查看 "Sent items" - 邮件的格式是什么?
可能是您的 Outlook 设置中的某些东西正在将其转换为纯文本!在旧版本的 Outlook 中,有一个选项 convert to Plain text for specific users。您是否正在使用这些版本中的任何一个并打开此选项?
在我的测试中,只有当我设置 .Body
而不是 .HtmlBody
时,我才会得到你的行为,即 newMail.Body = htmlBody;
我发现了问题。
在我发送的电子邮件中,我为 mailItem 设置了一些属性。
这与这篇文章有关...
Prevent winmail.dat in outlook (for gmail accounts)
如果我删除它们...一切正常。