Do you use Web Service to send emails?

Last updated by Igor Goldobin about 2 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();
try
{
    client.Host = "****.***.com.au";
    client.Port = 25;
    client.UseDefaultCredentials = true;
    
    MailAddress from = new MailAddress("test@ssw.com.au");
     
    string unrecAddy = "test@ssw.com.au";
    MailAddress to = new MailAddress(unrecAddy);

    MailMessage mailMessage = new MailMessage(from, to);

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

    client.Send(mailMessage);
    
}
catch(Exception ex)
{
    client.SendAsyncCancel();
    MessageBox.Show(ex.ToString());
}

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

We open source. Powered by GitHub