Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I am not familiar in how to create HTML Embeded emeil.
Currently I am using below code, It is work fine and send email
with plain text. It is not look nice. I need to formated embeded
email with logo and below information together to the email

Pls advice me.

Thank you in advance

Maideen

Below is code ( currently I am using , it is working fine)

HTML
Private Sub SendEmail(EmailAddress As String)

        Dim mail As New MailMessage()
        mail.To.Add(EmailAddress)
        mail.From = New MailAddress("xxxxxx@xxx.com")
        mail.CC.Add(Me.txtSAgentEmail.Text)
        mail.Subject = "Complaint"
        mail.Body = "Thank you for your suggession " & "<br>"
        mail.Body = mail.Body & " Date:- " & Date & "<br>"
        mail.Body = mail.Body & " Case ID:- " & caseid & "<br>"
        mail.Body = mail.Body & " Pakcage:- " & txtPKCode & "<br>"
        mail.Body = mail.Body & " Subscriber ID:- " & Code & "<br>"
        mail.Body = mail.Body & " Subscriber Name:- " & Name & "<br>"
        mail.Body = mail.Body & " Company:- " & Company & "<br>"
        mail.Body = mail.Body & " Job Title:- " & JobTitle & "<br>"
        mail.Body = mail.Body & " Address:- " & Address1 & "<br>"
        mail.Body = mail.Body & " Address:- " &BAddress2 & "<br>"
        mail.Body = mail.Body & " Post Code:- " & PosCode & "<br>"
        mail.Body = mail.Body & " City:- " & City & "<br>"
        mail.Body = mail.Body & " State:- " & State & "<br>"
        mail.Body = mail.Body & " Country:- " & Country & "<br>"
        mail.Body = mail.Body & " Tel:- " & TelNo & "<br>"
        mail.Body = mail.Body & " HP:- " & HPNo & "<br>"
        mail.Body = mail.Body & " Compalints:- " & Me.txtComplaints.Text & "<br>"
        mail.Body = mail.Body & " Status:- " & Status & "<br>"

        mail.IsBodyHtml = True

        Dim smtp As New SmtpClient()
        smtp.Host = "smtp.xxxx.com"
        smtp.EnableSsl = True
        Dim NetworkCred As New System.Net.NetworkCredential()
        NetworkCred.UserName = mail.From.Address
        NetworkCred.Password = "password"
        smtp.UseDefaultCredentials = False
        smtp.Credentials = NetworkCred
        smtp.Port = 587
        smtp.Send(mail)

      
    End Sub
Posted
Updated 23-Apr-15 18:42pm
v2
Comments
Sergey Alexandrovich Kryukov 24-Apr-15 0:42am    
What have you tried so far?
—SA

This just a matter of having appropriate Content-type: "text/html", and of course HTML context itself. Your mail body is not HTML, but I hope you know how to write it.

(More exactly, in MailMessage terminology, this is expressed as ContentType.MediaType property; please see the last link below.)

This is easy: the property System.Net.Mail.MailMessage.IsBodyHtml does the trick:
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage%28v=vs.110%29.aspx[^].

If you want to make only part of your mail HTML, it would be more tricky. You can create multi-part mail message. Parts plays the roles of attachments with different content-disposition values, such as embedded in the mail text when rendered, or downloadable attachments, or alternative views or linked resource. Then each part could have its own content type; one can be HTML another one a bitmap. For further information, see also:
https://msdn.microsoft.com/en-us/library/system.net.mail.attachment%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachmentbase%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachmentbase.contenttype%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mime.contenttype.mediatype%28v=vs.110%29.aspx[^].

Good luck,
—SA
 
Share this answer
 
int ExampleYourProductImage = 0;
StringBuilder strEmailBody = new StringBuilder();
strEmailBody.Append("<html>");
strEmailBody.Append("<head>");
strEmailBody.Append("</head>");
strEmailBody.Append("<body>");

strEmailBody.Append("<table width=\"400px\" style=\"border: 2px black solid; padding: 10px;\">");

// One Row Will Be Genearte Using Table Row And Table Columns.
strEmailBody.Append("<tr>");

strEmailBody.Append("<td style=\"width: 15%; padding-left: 15px; padding: 0; margin: 0;\">");
strEmailBody.Append("<img alt=\"Logo\" src=\"" + ExampleYourProductImage + "Newimages/logo.jpg \" height=\"60px\" width=\"150px\" />");
strEmailBody.Append("<td>");

strEmailBody.Append("<td style=\"width: 15%; text-align: right; padding-right: 15px;\">");
strEmailBody.Append("<h3>Receipt</h3>");
strEmailBody.Append("</td>");

strEmailBody.Append("</tr>");

strEmailBody.Append("</table>");
// Same You Can Design Your HTML Mail Using Div, Table Row And Table Columns.

strEmailBody.Append("</body></html>");

string Message = strEmailBody.ToString();
string strEmailSub = "Example HTML Mail";


MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add("ToMail");
mail.From = new MailAddress("FromMail");
mail.Subject = "Subject";
mail.Body = Message;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "Host";
smtp.Port = 000;
smtp.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationSettings.AppSettings["YourMail"].ToString(), System.Configuration.ConfigurationSettings.AppSettings["YourPassword"].ToString());

smtp.EnableSsl = true;
smtp.Send(mail);

Vikas Joshi
Senior Software Developer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900