【发布时间】:2020-01-24 22:38:13
【问题描述】:
我正在测试使用 CID 标签发送带有图像的电子邮件,我制作了一个只运行邮件的桌面应用程序,程序要求我也将它们放在项目的调试文件夹中,而不是我放置的文件夹他们,现在我将它发送到 Windows 服务,但它告诉我
找不到文件'C:\WINDOWS\system32\ img.png
我已经把图片放到那个文件夹里了,但是还是出现同样的错误,图片类型是 .png,这是我的电子邮件代码
private void SendMAil()
{
string htmlBody = "<!DOCTYPE html>" +
"<html xmlns = 'http://www.w3.org/1999/xhtml'>" +
"<head>" +
"<meta http - equiv = 'Content-Type' content = 'text/html; charset=UTF-8'/>" +
"<title> Demystifying Email Design</title>" +
"<meta name = 'viewport' content = 'width=device-width, initial-scale=1.0'/>" +
"</head>" +
"<body style = 'margin: 0; padding: 0;'>" +
"<table align = 'center' border = '0' cellpadding = '0' cellspacing = '0' width = '900' > " +
"<tr>" +
"<td align='left' bgcolor='#F8F8F8' style='padding: 15px 0 15px 0;border-bottom-width:6px;border-bottom-color:#225100;border-bottom-style:solid;'>" +
" <img src=\"cid:img\"' width='90' height='40'>" +
"</td>" +
"</tr>" +
"<tr>" +
"<td bgcolor = '#ffffff' style='padding:30px 30px 65px 30px'>" +
"HELLO!!!"+
"</td>" +
"</tr>" +
"<tr>" +
"<td bgcolor = '#FFFFFF' align='center' style='padding: 15px 0 15px 0;border-top-width:1px;border-top-color:#FA5300;border-top-style:solid;'>" +
"</td>" +
"</tr>" +
"</table>" +
"</body>" +
"</html>";
AlternateView avHtml = AlternateView.CreateAlternateViewFromString
(htmlBody, null, MediaTypeNames.Text.Html);
LinkedResource inline = new LinkedResource("img.png", MediaTypeNames.Image.Jpeg);
inline.ContentId = "img";
avHtml.LinkedResources.Add(inline);
Attachment att1 = new Attachment(@"img\img.png");
att1.ContentDisposition.Inline = true;
mail.From = new MailAddress("xx@xx.com");
mail.To.Add("xx@xx.com");
mail.Subject = "Alerta Estado Tags";
mail.Body = inline.ContentId;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient
{
Credentials =
new NetworkCredential("xx@xx.com", "****"),
Host = "smtp.gmail.com",
Port = 000,
EnableSsl = true
};
smtp.Send(mail);
mail.Dispose();
}
我将图像放在哪里?路径是什么?
【问题讨论】:
标签: c# asp.net .net visual-studio windows-services