Moose Pickard

Moose Pickard

  • NA
  • 64
  • 70.5k

Problem with sending mail

Nov 26 2010 10:55 AM
Hi
I'm struggling with sending mail with c#.
This is the code I found on the web.
I don't have a server so I think I can't use something in this code.
I'm not familiar with the mail syntax smtp etc.

I figured I could do this the easy way.
Create a webmail account such as gmail, give the password and username and use this.
But this code doesn't work like this.
If you know a working snippet then please refer me to it.

public void SendMail(){

MailMessage mail = new MailMessage();

mail.To.Add([email protected]);

mail.From = new MailAddress([email protected]);

mail.Subject = "Test";
 

string Body = "Lorem ipsum dolor sit amet,...
";
mail.Body = Body;
SmtpClient smtp = new SmtpClient("smtp.gmail.com");

	try{

	smtp.Send(mail);

	}

	catch (Exception ex){

	MessageBox.Show(ex.ToString());
			  
	}

}

Thank You

Answers (2)