如何在身体内容中附加图像.我写了下面的代码
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); string UserName = "xyz@someorg.com"; string Password = "my password"; message.To.Add(new System.Net.Mail.MailAddress("toaddress@toadddress.com")); message.From = new System.Net.Mail.MailAddress("fromaddress@fromaddress.com"); message.Subject = "test subject"; message.Body = "<img src=@'C:\\Sunset.jpg'/>"; message.IsBodyHtml = true; System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); smtpClient.Host = "hostname"; smtpClient.Port = 25; smtpClient.Credentials = new System.Net.NetworkCredential(UserName,Password); smtpClient.Send(message);
解决方法
string attachmentPath = Environment.CurrentDirectory + @"\test.png"; Attachment inline = new Attachment(attachmentPath); inline.Contentdisposition.Inline = true; inline.Contentdisposition.dispositionType = dispositionTypeNames.Inline; inline.ContentId = contentID; inline.ContentType.MediaType = "image/png"; inline.ContentType.Name = Path.GetFileName(attachmentPath); message.Attachments.Add(inline);
原文地址:https://www.jb51.cc/csharp/98580.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。