Announcement

Collapse
No announcement yet.

How to send HTML Embedded Email?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to send HTML Embedded Email?

    Hello,

    Iím newbie in .NET and I want to create HTML Embedded email.
    Presently I have code and it works fine but it send email with plain text. It is not look pleasant.
    I want to formatted embedded email with logo and below information together to the email

    Thanks in advance

  • #2
    Hi Hadley,

    can you post code here?
    So that we can provide you the exact steps.

    Comment


    • #3
      Hi Kelvin,
      Thanks for your reply.

      Here is code:
      Code:
      Private Sub SendEmail(EmailAddress As String)
      
              Dim mail As New MailMessage()
              mail.To.Add(EmailAddress)
              mail.From = New MailAddress("[email protected]")
              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

      Comment


      • #4
        Hi Hadley,
        Given below code is in C# but it is similar to VB. And add other properties as needed.

        Code:
        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);

        Comment

        Working...
        X