SendEmail with smtp username and password

  • Thread starter Thread starter Adam Milligan
  • Start date Start date
A

Adam Milligan

Hello all-

I am using visual studio 2008 .net 3.5 and I am trying to send an e-mail
from a web application using SmtpClient (see below, the numbers have been
changed to protect the innocent)

protected static void SendEMail(string sTo, string sFrom, string sSubject,
string sMessage)
{
//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress(sFrom);
mail.To.Add(sTo);

//set the content
mail.Subject = sSubject;
mail.Body = sMessage;

//send the message
SmtpClient smtp = new SmtpClient("192.168.1.123",25);
smtp.Send(mail);

}


The catch is that the information I recieved from the powers that control
the SMTP server that I HAVE to use indicates that I need to supply a username
and password. I have the username and password that I need to use, but I
have no way to add them as parameters. Any help would be greatly appreciated.

Thanks,

Adam
 
//send the message
SmtpClient smtp = new SmtpClient("192.168.1.123",25);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("username", "password")
smtp.Send(mail);
 
Back
Top