Robert J.
Robert J.

Reputation: 2701

c# Send Email using Process.Start

I want to send simple email with no attachment using default email application.

I know it can be done using Process.Start, but I cannot get it to work. Here is what I have so far:

string mailto = string.Format("mailto:{0}?Subject={1}&Body={2}", "[email protected]", "Subject of message", "This is a body of a message");
System.Diagnostics.Process.Start(mailto);

But it simply opens Outlook message with pre-written text. I want to directly send this without having user to manually click "Send" button. What am I missing?

Thank you

Upvotes: 3

Views: 12801

Answers (3)

adityaswami89
adityaswami89

Reputation: 583

You need to do this:

SmtpClient m_objSmtpServer = new SmtpClient();
MailMessage objMail = new MailMessage();
m_objSmtpServer.Host = "YOURHOSTNAME";
m_objSmtpServer.Port = YOUR PORT NOS;

objMail.From = new MailAddress(fromaddress);
objMail.To.Add("TOADDRESS");

objMail.Subject = subject;
objMail.Body = description;
m_objSmtpServer.Send(objMail);

Upvotes: 2

Ignac
Ignac

Reputation: 59

You need to do this :

string mailto = string.Format("mailto:{0}?Subject={1}&Body={2}", "[email protected]", "Subject of message", "This is a body of a message");
mailto = Uri.EscapeUriString(mailto);
System.Diagnostics.Process.Start(mailto);

Upvotes: 5

The-First-Tiger
The-First-Tiger

Reputation: 1574

I'm not sure about Process.Start() this will probably always only open a mail message in the default Mail-App and not send it automatically.

But there may be two alternatives:

Upvotes: 3

Related Questions