在C#中附加邮件正文中的图像

如何在身体内容中附加图像.我写了下面的代码
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);

代码很好,因为我也收到了消息,但图像在身体内部[X]而不是图像.
怎么解决这个?路径是正确的?

解决方法

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

参考:Send an Email in C# with Inline attachments

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...