Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailMessage c# - How to make it HTML and add images etc?

Tags:

string to = "[email protected]";  string body = "Test";  SmtpClient SMTPServer = new SmtpClient("127.0.0.1");  MailMessage mailObj = new MailMessage(urEmail, to, subject, body);  SMTPServer.Send(mailObj); 

This is how i am currently sending a test email. How do i make this html and be able to make the email sent out look better by adding images etc?

Thanks

like image 321
Beginner Avatar asked Oct 24 '11 08:10

Beginner


People also ask

What does MailMessage class do in C#?

Instances of the MailMessage class are used to construct email messages that are transmitted to an SMTP server for delivery using the SmtpClient class. The sender, recipient, subject, and body of an email message may be specified as parameters when a MailMessage is used to initialize a MailMessage object.

What is IsBodyHtml?

IsBodyHtml states that your message is HTML formatted. If you were only sending a single view of HTML, this is all you need.


1 Answers

On the MailMessage set the property IsBodyHtml to true.

string to = "[email protected]"; string body = "Test"; SmtpClient SMTPServer = new SmtpClient("127.0.0.1"); MailMessage mailObj = new MailMessage(urEmail, to, subject, body);  mailObj.IsBodyHtml = true; // This line  SMTPServer.Send(mailObj); 
like image 70
swapneel Avatar answered Oct 05 '22 13:10

swapneel