如何解决从 C# 发送邮件时不显示正文消息
我写了一个下面的代码来发送带有“LinkedResource”的邮件。它按照我们的要求工作正常,但没有显示正文消息。请检查下面的代码并告知为什么没有显示正文消息。
private void MailSend()
{
MailMessage Mail = new MailMessage();
Mail.From = new MailAddress("edp.kharind@khindia.com");
Mail.To.Add("edp.kharind@khindia.com");
Mail.Subject = "This is Image Test.";
Mail.Body = "This is the body of the email45454545";
LinkedResource LinkedImage = new LinkedResource(@"D:\GatePass.JPG");
LinkedImage.ContentId = "MyPic";
//Added the patch for Thunderbird as suggested by Jorge
LinkedImage.ContentType = new ContentType(MediaTypeNames.Image.Jpeg);
AlternateView htmlView = AlternateView.CreatealternateViewFromString(
"You should see image next to this line. <img src=cid:MyPic>",null,"text/html");
htmlView.LinkedResources.Add(LinkedImage);
Mail.AlternateViews.Add(htmlView);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
SmtpClient smtp = new SmtpClient("smtp.office365.com",587);
try
{
//smtp.Send(Mail);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new System.Net.NetworkCredential("edp.kharind@khindia.com","xyz");
smtp.TargetName = "STARTTLS/smtp.office365.com";
smtp.Send(Mail);
}
catch (SmtpException ex)
{
//Logger.LogException(ex);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。