2017-07-27 28 views
3

我嘗試將HTML發送到gmail帳戶,從Gmail到SMTP服務器。爲什麼編碼標頭內容類型:text/html;在Outlook插件中使用MailItem時缺少GMAIL的SMTP服務器:SMTP.GMAIL.COM?

如果我編寫這樣的代碼併發送HTML,則沒有問題。

 MailMessage mail = new MailMessage("[email protected]", 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 隨着頭:

Subject: Test 
Content-Type: text/html; charset=utf-8 
Content-Transfer-Encoding: base64 

PGh0bWw==(該基地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 


[email protected] 


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

任何建議嗎?

回答

2

我發現這個問題。

在我發送的電子郵件中,我爲mailItem設置了一些屬性。

,這是與此相關的文章...

Prevent winmail.dat in outlook (for gmail accounts)

如果刪除它們......一切工作正常。

+0

幹得好,也許鏈接到你問的變體上的這個答案,將來會幫助別人。 –

1

我測試過你的Outlook郵件代碼發送郵件,我可以在我的Gmail帳戶中正確地看到HTML格式的郵件。我的環境是:VS 2015/Outlook 2016

有趣的是,在我的測試中,我看到了兩個 - Content-Type: text/plain;Content-Type: text/html;。該代碼僅設置HtmlBody

enter image description here

您發送後,郵件,如果您在Outlook中查看您的「已發送郵件」 - 什麼是電子郵件的格式?

可能是在您的Outlook設置中將其轉換爲純文本!在舊版Outlook中,有一個選項convert to Plain text for specific users。任何機會,你使用這些版本中的任何一個,並打開此選項?

在我的測試,我知道你的行爲,只有當我設置.Body,而不是.HtmlBody,即newMail.Body = htmlBody;

+0

您需要檢查Gmail收到的項目。在展望方面,一切都很好。您還可以在Microsoft論壇https://social.msdn.microsoft.com/Forums/en-US/cf09d3fa-27ba-4ac6-9959-d72247be5bf0/try-to-send-html-email上查看我的文章-from-outlook-outlookmailitem-and-passing-by-gmail-smtp-server?forum = outlookdev –

+0

另一個想法 - 你可以嘗試驗證你的HTML嗎? gmail不喜歡你的HTML中有什麼東西? – Subbu

+0

好問題,我會嘗試 –

相關問題