3

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}", "to@user.com", "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

Robert J.
  • 2,631
  • 8
  • 32
  • 59
  • 4
    Why are expecting that to be like that? I'm glad no random application can send email using my email program without me knowing or seeing anything. – Maarten Oct 16 '14 at 12:03
  • use the `SmtpClient` class. – kennyzx Oct 16 '14 at 12:04
  • If problem occurs within the application, I want to automatically send error log to system administrator. – Robert J. Oct 16 '14 at 12:05
  • Automating Outlook via COM Interop is the best way if for whatever reason you *must* use Outlook. For the command line see; [Sending email from Command-line via outlook without having to click send](http://stackoverflow.com/questions/15433202/sending-email-from-command-line-via-outlook-without-having-to-click-send). For a general solution for other e-mail clients, your out of luck - there is no such common interface. – Alex K. Oct 16 '14 at 12:09
  • The process start will not fully automate the sending of the email. It will only open it ready to send (as you have seen) – landoncz Oct 16 '14 at 12:10

3 Answers3

5

You need to do this :

string mailto = string.Format("mailto:{0}?Subject={1}&Body={2}", "to@user.com", "Subject of message", "This is a body of a message");
mailto = Uri.EscapeUriString(mailto);
System.Diagnostics.Process.Start(mailto);
Ignac
  • 59
  • 1
  • 1
3

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:

Community
  • 1
  • 1
The-First-Tiger
  • 1,574
  • 11
  • 18
2

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);
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
adityaswami89
  • 573
  • 6
  • 15