为什么通过带有C#的asp.net在邮件发送过程中,Outlook中没有显示图像? [英] Why Image is not shown in Outlook during the mail sending process via asp.net with C#?
本文介绍了为什么通过带有C#的asp.net在邮件发送过程中,Outlook中没有显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法通过asp.net使用c#2.0 / c#1.1发送邮件时查看图像。我的代码如下:
string strMailContent = 欢迎新用户;
string fromAddress = alexander.junior @ nestgroup.net跨度>;
string toAddress = alexander.junior @ nestgroup.net跨度>;
string contentId = image1跨度>;
string path = Server.MapPath( @ 图片/ welfare.jpg跨度>); // 我的徽标位于图像文件夹中
MailMessage mailMessage = new MailMessage(fromAddress,toAddress);
mailMessage.Bcc.Add( alexander.junior@nestgroup.net); // 将您的ID放在此处
mailMessage.Subject = 欢迎新用户;
LinkedResource logo = new LinkedResource(path);
logo.ContentId = companylogo;
// 在下一行完成HTML格式以显示我的徽标
AlternateView av1 = AlternateView.CreateAlternateViewFromString( < html>< body>< img src = cid:companylogo /> < br>< / body>< / html> + strMailContent, null ,MediaTypeNames.Text.Html);
av1.LinkedResources.Add(logo);
mailMessage.AlternateViews.Add(av1);
mailMessage.IsBodyHtml = true ;
SmtpClient mailSender = new SmtpClient( mail .nestgroup.net跨度>); // 如果您在开发服务器中,请使用此
mailSender.Send(mailMessage);
解决方案
如果你想嵌入身体使用
< pre lang =c#> 尝试
{
// 从本地磁盘添加图像附件
附件oAttachment = oMail.AddAttachment( d:\\test.gif);
// 将附件指定为嵌入图像
< span class =code-comment> // contentid可以是任何字符串。
string contentID = test001 @ host;
oAttachment.ContentID = contentID;
oMail.HtmlBody = < html>< body>这是一个< img src = \ cid:< br mode = hold / > + contentID + \ >嵌入图片。< / body>< / HTML>中跨度>;
Console.WriteLine( 开始发送包含嵌入图片的电子邮件......跨度>);
oSmtp.SendMail(oServer,oMail);
Console.WriteLine( 电子邮件已成功发送!);
}
catch (异常ep)
{
Console.WriteLine( 无法发送包含以下错误的电子邮件:);
Console.WriteLine(ep.Message);
}
使用图片src的完整网址
AlternateView av1 = AlternateView.CreateAlternateViewFromString( < html>< body>< img src = http: // www.yourdomain.com/images/companylogo.jpg/>< br> < / br>< / body>< / html>+ strMailContent,null,MediaTypeNames.Text.Html);
I am unable to view the Image on sending mail via asp.net with c# 2.0/c# 1.1. My code as follows:
string strMailContent = "Welcome new user";
string fromAddress = "alexander.junior@nestgroup.net";
string toAddress = "alexander.junior@nestgroup.net";
string contentId = "image1";
string path = Server.MapPath(@"Images/welfare.jpg"); // my logo is placed in images folder
MailMessage mailMessage = new MailMessage(fromAddress, toAddress);
mailMessage.Bcc.Add("alexander.junior@nestgroup.net"); // put your id here
mailMessage.Subject = "Welcome new User";
LinkedResource logo = new LinkedResource(path);
logo.ContentId = "companylogo";
// done HTML formatting in the next line to display my logo
AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html><body><img src=cid:companylogo/><br></body></html>" + strMailContent, null, MediaTypeNames.Text.Html);
av1.LinkedResources.Add(logo);
mailMessage.AlternateViews.Add(av1);
mailMessage.IsBodyHtml = true;
SmtpClient mailSender = new SmtpClient("mail.nestgroup.net"); //use this if you are in the development server
mailSender.Send(mailMessage);
解决方案
If you want to embedded in to body use
try { // Add image attachment from local disk Attachment oAttachment = oMail.AddAttachment( "d:\\test.gif" ); // Specifies the attachment as an embedded image // contentid can be any string. string contentID = "test001@host"; oAttachment.ContentID = contentID; oMail.HtmlBody = "<html><body>this is a <img src="\"cid:"<br" mode="hold" /> + contentID + "\"> embedded image.</body></html>"; Console.WriteLine("start to send email with embedded image..."); oSmtp.SendMail(oServer, oMail); Console.WriteLine("email was sent successfully!"); } catch (Exception ep) { Console.WriteLine("failed to send email with the following error:"); Console.WriteLine(ep.Message); }
Use full url for image src
AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html><body><img src="http://www.yourdomain.com/images/companylogo.jpg" /><br></br></body></html>" + strMailContent, null, MediaTypeNames.Text.Html);
这篇关于为什么通过带有C#的asp.net在邮件发送过程中,Outlook中没有显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文