2 Replies - 1683 Views - Last Post: 29 July 2009 - 11:10 AM Rate Topic: -----

#1 harish.k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 15-July 09

send email from windowsform

Post icon  Posted 29 July 2009 - 04:13 AM

HI,

I want to send email from windowsform and the bodypart of the email should contain htmlpage . I can send the plain text but not html

try
			{
				MailMessage mail = new MailMessage();
				SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

				mail.From = new MailAddress("from add");
				mail.To.Add("toadd");
				mail.Subject = "Test Mail";
				
				mail.IsBodyHtml = true;
				string htmlBody;

			   
				htmlBody = "<b>Welcome to CodeDigest.Com</b>";
			  
				mail.Body = htmlBody;
				
				SmtpServer.Port = 25;
				SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
				SmtpServer.EnableSsl = true;
			   // MessageBox.Show("will send");
				SmtpServer.Send(mail);
			   
				
				MessageBox.Show("mail Send");
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.ToString());
			}



Is This A Good Question/Topic? 0
  • +

Replies To: send email from windowsform

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: send email from windowsform

Posted 29 July 2009 - 05:16 AM

This should work:

MailMessage mailMsg = new MailMessage("from","to");
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<b>Hey!</b>", null, "text/html");
mailMsg.AlternateViews.Add(htmlView);

SmtpClient smtp = new SmtpClient("smtp.gmail.com",25);
smtp.Credentials = new NetworkCredential("yourID", "yourPassword");

smtp.Send(mailMsg);


Was This Post Helpful? 0
  • +
  • -

#3 harish.k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 15-July 09

Re: send email from windowsform

Posted 29 July 2009 - 11:10 AM

thankyou for your help


Right now I am able to display html contents as plain text.

I am able to get the contents from html tags. but my problem is that
I want to display html contents with backcolour and other attributes as I have in the htmlpage in the Emailbody part.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1