I'm trying to develop a class library that contains some of the code I don't like having to type into multiple applications. So I need help figuring out if my coding is right on this one? I don't have an SMTP server to test with.
public void Send(String client, Int32 port, String username, String password, String to, String from, String subject, String body)
{
SmtpClient mClient = new SmtpClient(client, port);
mClient.Credentials = new NetworkCredential(username, password);
MailMessage mMessage = new MailMessage();
mMessage.To.Add( new MailAddress(to));
mMessage.From = new MailAddress(from);
mMessage.Subject = subject;
mMessage.Body = body;
try
{
mClient.Send(mMessage);
}
catch (Exception e)
{
MessageBox.Show("Could not send message do to the following reason: " + e.Message);
}
All help is appreciated; this was coded by playing around in the .Net namespace; unfortunately I don't know if it's accurate.