Do you use Web Service to send emails?

Last updated by Igor Goldobin 4 months ago.See history

In a Windows application, if you need to send mail, please use a WebService to do this, because using WebService to send emails is safer.You don't need to store the email server configuration in your application.config file, which can be installed on the client and be exposed to someone who could take advantage of it.

SmtpClient client = new SmtpClient();
    client.Host = "****.***";
    client.Port = 25;
    client.UseDefaultCredentials = true;

    MailAddress from = new MailAddress("[email protected]");

    string unrecAddy = "[email protected]";
    MailAddress to = new MailAddress(unrecAddy);

    MailMessage mailMessage = new MailMessage(from, to);

    mailMessage.Subject = "aaa";
    string strVer = "aaa";
    mailMessage.Body = "aaa";


catch(Exception ex)

Bad example - Send mail without webservice

Emailer.PubicFunction pf = new EmailWebServices.Emailer.Publiction();
pf.SendMail("Test", textBox3.Text, textBox1.Text, textBox2.Text, false, "", null);

Good example - Send mail use webservice

Adam Cogan
We open source. Powered by GitHub