C#发送内置图片的html格式邮件
发布时间:2020-12-15 17:56:53 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 MailMessage m = new MailMessage();m.From = new MailAddress("[email?protected]","Raja Item");m.To.Add(new MailAddress("[email?protected]","Se
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 MailMessage m = new MailMessage(); m.From = new MailAddress("[email?protected]","Raja Item"); m.To.Add(new MailAddress("[email?protected]","Sekaran Uma")); m.Subject = "html email with embedded image coming!"; // Create the HTML message body // Reference embedded images using the content ID string htmlBody = "<html><body><h1>Picture</h1><br><img src="cid:Pic1"></body></html>"; AlternateView avHtml = AlternateView.CreateAlternateViewFromString (htmlBody,null,MediaTypeNames.Text.Html); // Create a LinkedResource object for each embedded image LinkedResource pic1 = new LinkedResource("pic.jpg",MediaTypeNames.Image.Jpeg); pic1.ContentId = "Pic1"; avHtml.LinkedResources.Add(pic1); // Create an alternate view for unsupported clients string textBody = "You must use an e-mail client that supports HTML messages"; AlternateView avText = AlternateView.CreateAlternateViewFromString (textBody,MediaTypeNames.Text.Plain); m.AlternateViews.Add(avHtml); m.AlternateViews.Add(avText); // Send the message SmtpClient client = new SmtpClient("smtp.sharejs.com"); client.Send(m); 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |