3
Answers

Email format

ASPbee

ASPbee

13y
3.1k
1
Hi,

    I have an automatic windows service to send out the emails as scheduled. But the email message i have been receiving is appearing in plain text instead of HTML format. Can someone throw me few tips or ideas where i am making a mistake.

thanks 

Answers (3)
0
ASPbee

ASPbee

NA 40 32k 13y
Thanks for all your responses. But unfortunately i am not sure its still not working. Can you please go through the code below and let me know where i am doing wrong or if it needs any further modification.

private bool MailSend(bool SMS,string EmailFrom, string EmailTo, string EmailSubject, string EmailBody,ref Exception parmExc)
  {
 MailMessage msg=null;
 try
 {
msg = new MailMessage(EmailFrom, EmailTo, EmailSubject, EmailBody);
if (!SMS)
{
msg.IsBodyHtml = true;
}
SmtpClient client = new SmtpClient("localhost");
client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
             msg.EmailBody = "http://localhost:3171/WebApplication1/frmResponse.aspx?TraxIterID="+ ds.Tables[0].Rows[i].ItemArray[3].ToString()"";
client.Send(msg);
if (DebugMailSending)
{
StringBuilder sbMailSendDebug = new StringBuilder();
sbMailSendDebug.AppendFormat("EMail Sent => From={0};To={1};Subject={2};Body={3}", EmailFrom, EmailTo, EmailSubject, EmailBody);
DebugMessage(sbMailSendDebug.ToString());
}
parmExc = null;
return true;
 }
 catch (Exception exc1)
 {
parmExc = exc1;
return false;
 }
 finally
 {
DisposeIfNotNull(msg);
 }
  } // end MailSend



0
Abhimanyu K Vatsa

Abhimanyu K Vatsa

NA 50.9k 12.4m 13y
hey you have to build HTML mail by setting the IsBodyHTML to true. Here you go:

public void sendmail(string v3, string v2, string v1) //replace the parameter or delete if needed
    {
        string smsg = "Thank you for posting Article on our site, your post is very important for us:<br><br>";
        smsg += "<br><b>Title of Post: </b><br>" + "<a href=" + v1 + ">" + v2 + "</a>";
        smsg += "<br><b>Description of Post: </b><br>" + v3;
        smsg += "<br><br><br><br>";
        smsg += "<b>Administrator</b>";
//in above lines I'm building HTML body for mailing, here you can use any standerd html tags

        MailMessage message = new MailMessage();
        try
        {
            string ToEmailIDToSendEmail = getEmailAddressOfUser(); //i'm just receiving TO email address from SQL Server DB by calling function
            message.To.Add(new MailAddress(ToEmailIDToSendEmail)); //here you can directly use the TO mail
            message.From = new MailAddress("use the same address i.e. ur username that will be used below");

            message.Subject = "your email subject will be here";
            message.Body = smsg;
            message.IsBodyHtml = true; //always set this to true for html based mail

            SmtpClient client = new SmtpClient();
            client.Port = 587; // I uses port 587 for gmail, replace this if you needed
            client.Host = "smtp.gmail.com"; //replace the host, i will be using gmail
            System.Net.NetworkCredential nc = new System.Net.NetworkCredential("senderemailid or say user name", "password-of-mail-id");
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = nc;
            client.Send(message);
        }
        catch
        {
            //do your catch job here;
        }
    }

Hope this helps.
0
Ravishankar Singh

Ravishankar Singh

NA 3.4k 458.3k 13y
Hi,
You can match your code from the below:
Look into Bold section.
MailMessage mail = new MailMessage(); mail.To = "me@mycompany.com"; mail.From = "you@yourcompany.com"; mail.Subject = "this is a test email."; mail.BodyFormat = MailFormat.Html; mail.Body = "this is my test email body.<br><b>this part is in bold</b>"; SmtpMail.SmtpServer = "localhost";  //your real server goes here SmtpMail.Send( mail );
Did you used the mailformat option? mail format used class system
"System.Web.Mail.MailFormat"
Hope this will helpful for u. :)