0
private void button1_Click(object sender, EventArgs e)
{
    if (check() == true)  // True: sends mail
    {
        try
        {
            // Mailmessage wordt gedeclareerd (hiermee kan je mails sturen)
            MailMessage mail = new MailMessage(); 
            // SMTP server van GMAIL wordt hier aangegeven
            SmtpClient smtpali = new SmtpClient("smtp.gmail.com");                

            mail.From = new MailAddress("xxxxxx@gmail.com");
            mail.To.Add("xxxxxx@gmail.com");
            mail.Subject = "Test Mail";
            mail.Body = "Beste gebruiker";
            smtpali.Port = 587;
            smtpali.Credentials = new NetworkCredential("user", "xxxxxxx");
            smtpali.EnableSsl = true;
            smtpali.Send(mail);
            MessageBox.Show("Mail is verzonden!");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
    else
    {
        MessageBox.Show("Verkeerde combinatie!");
    }
}

Hello everyone. I've created a login system in C# and just finished the "resend password" form. This form sends a mail to the user with his password (plain and simple). I was wondering, what way can I use HTML markup in the body:

mail.Body = "content here"

I tried using:

mail.Body = "<h1>content here</h1>" 

...et cetera but that is ofcourse plain text. Any suggestions for my case?

JG in SD
  • 5,427
  • 3
  • 34
  • 46
David Asssad
  • 41
  • 1
  • 9

3 Answers3

2

Set MailMessage.IsBodyHtml to true.

mail.IsBodyHtml = true;
jrummell
  • 42,637
  • 17
  • 112
  • 171
1

You should set IsBodyHtml to true for this to work.

Efran Cobisi
  • 6,138
  • 22
  • 22
0

Try using mail.IsBodyHtml = true; in your code

Olivier Picault
  • 338
  • 5
  • 14