如何以HTML格式发送邮件,我的要求是在邮件中发送嵌入的图像。 [英] How to send mail in HTML format, my requirement is to send an embedded image in the mail.

查看:627
本文介绍了如何以HTML格式发送邮件,我的要求是在邮件中发送嵌入的图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码发送带有邮件的图片,但邮件发送给用户只收到字符串格式。



[HttpPost]

public ActionResult SignUp(tbuser user)

{

try

{

var uemail = user .uemail;

var upassword = user.upassword;

db.tbusers.Add(user);

db.SaveChanges();

MailMessage mail = new MailMessage();

mail.To.Add(uemail);

mail.From = new MailAddress(nadeem786chd @ gmail.com);

mail.Subject =来自网站的确认邮件;

字符串路径= Server.MapPath(@〜/ Content / images /istmailer2.gif);

String Body =;

LinkedResource logo = new LinkedResource(path);

logo.ContentId =广告标识;


身体=身体+标识;

身体=身体+;

Body = Body +您已成功在GoAir上创建帐户请使用您的登录邮件和通行证登录您的帐户单词
;

Body = Body +您将被重定向到网站的登录页面;

Body = Body +Your Email:+ uemail;

Body = Body +密码:+ upassword;

mail.Body = Body;

mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();

smtp.Host =smtp.gmail.com;

smtp.Port = 587;

smtp.UseDefaultCredentials = false;

smtp.Credentials = new System.Net.NetworkCredential

(cssoft.net@gmail.com.Trim(),lkjI *& yu&。Trim());

smtp.EnableSsl = true;

smtp.Send(邮件);

}

catch

{



}

返回查看(登录);

}

I am trying to send Image with the mail using below code but mail send to the user only recieves in string format.

[HttpPost]
public ActionResult SignUp(tbuser user)
{
try
{
var uemail = user.uemail;
var upassword = user.upassword;
db.tbusers.Add(user);
db.SaveChanges();
MailMessage mail = new MailMessage();
mail.To.Add(uemail);
mail.From = new MailAddress("nadeem786chd@gmail.com");
mail.Subject = "Confirmation mail from site";
string path = Server.MapPath(@"~/Content/images/istmailer2.gif");
String Body = "";
LinkedResource logo = new LinkedResource(path);
logo.ContentId = "Advertisement Logo";

Body = Body + logo;
Body = Body + "";
Body = Body + "You Have Successfully created your Account on GoAir Please login to your account using your Login Mail and Pass word
";
Body = Body + "You will be redirected to website's Login Page ";
Body = Body + "Your Email: " + uemail;
Body = Body + "Password: " + upassword;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential
("cssoft.net@gmail.com".Trim(), "lkjI*&yu&".Trim());
smtp.EnableSsl = true;
smtp.Send(mail);
}
catch
{

}
return View("SignIn");
}

推荐答案

有一个请查看此System.Net.Mail常见问题解答网站 [ ^ ],特别是以下两个条目:



如何发送简单的Html电子邮件? [ ^ ]

怎么做我将图片嵌入电子邮件中? [ ^ ]
Have a look at this System.Net.Mail FAQ site[^], particularly the following two entries:

How do I send a simple Html email?[^]
How do I embed images in an email?[^]


谢谢你们很快回复

我还有一个问题,我怎么能生成pdf的预订机票详情,并通过电子邮件发送给用户。



我正在网上预订机票网站预订请尽快回复。

谢谢!
Thank You Sir for soon reply
I have One more query that How I can generate pdf of book ticket details and send via email to user.

I am making a website on Online Airlines ticket booking please reply asap.
Thank You!


这篇关于如何以HTML格式发送邮件,我的要求是在邮件中发送嵌入的图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆