您好,我想从 Asp.net 发送图像邮件。
我收到这样的错误 :: ' http://domain-name.com/slideshow/original/Jellyfish.png ' 不是有效的虚拟路径。
我的代码是:
try
{
string _SenderEmailID = ReciverEmailID.Text.ToString();
string _ReciverEmailID = ReciverEmailID.Text.ToString();
string _Sender = FullName.Text.ToString();
string post = "JellyBeans.png";
string ImagePath = "http://www.domain-name.com/slideshow/original/";
string iImage = ImagePath + post;
img1.ImageUrl = ImagePath;
MailMessage mail = new MailMessage();
mail.To.Add(_ReciverEmailID);
mail.From = new MailAddress(_SenderEmailID);
mail.Subject = _Sender + " sent you a mail from 'www.domain-name.com";
string Body = "<img alt=\"\" hspace=0 src=\"cid:imageId\" align=baseline border=0 >";
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
LinkedResource imagelink = new LinkedResource(Server.MapPath(ImagePath)+ @post, "image/png");
imagelink.ContentId = "imageId";
imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlView.LinkedResources.Add(imagelink);
mail.AlternateViews.Add(htmlView);
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtp.Send(mail);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}