Question

I have a C# Windows forms application with an address book. On the one form there is a text box which displays the contacts email address (from a data table). I'd like to have a button next to it, when clicked it will open up my email client, with the email address entered in.

I understand you can use System.Diagnostics.Process.Start(mailto:example@example.com) to send an email to the specified contact. But how can I get it to send it to the value entered in the text box

Was it helpful?

Solution

Sending emails by pushing it to a default mail client Process.Start('mailto:xxx') is not a good idea. There could be no default email client defined or the default application could just not be configured.

Either way, users will get messages coming not from your application but from the external application.

A better idea is to have an explicit email client configuration for your application and even yet better - allow users to configure email client.

By email client I mean:

  • SMTP server
  • port (default: 25)
  • username
  • password

With these, your application can easily send emails through the relay SMTP server:

http://msdn.microsoft.com/pl-pl/library/swas0fwc%28v=vs.110%29.aspx

MailMessage message = new MailMessage(from, to);

message.Subject = subject;
message.Body = body;

SmtpClient client = new SmtpClient(server);
client.Credentials = new NetworkCredentials( username, password );

client.Send(message);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top