开发者

Sending Mail with embeded image in ASP.NET

I want to send a mail with embeded image in ASP.NET

How can i do that?

R开发者_开发知识库egards Soner


There are generally two ways of doing this, whichever is preferred is up to you.

To literally "embed" the image in the email message itself, you'll want to add it as a Linked Resource and reference the attached resource in the email's HTML.

Alternatively, and more simply, if the image is hosted in a public location then you can just reference that location in the HTML of the email.

Based on the question, it sounds like you are preferring the former approach, but the latter is available as well.


MailAddress sendFrom = new MailAddress(txtFrom.Text);
MailAddress sendTo = new MailAddress(txtTo.Text);

MailMessage myMessage = new MailMessage(sendFrom, sendTo);

MyMessage.Subject = txtSubject.Text;
MyMessage.Body = txtBody.Text;

Attachment attachFile = new Attachment(txtAttachmentPath.Text);
MyMessage.Attachments.Add(attachFile);

SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
emailClient.Send(myMessage);


I believe you can either attach the files and refer them, or alternatively, like in regular HTML, embed them encoded in Base64.


You can go through this link

http://www.dotnetspider.com/resources/41465-Send-Formatted-outlook-email-from-NET-C.aspx

Sample project is also attached.

It shows how to put the link of the image in the application in the html template and send emails.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜