SendEmail with smtp username and password

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
 
S

Scott Stark

//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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top