468,736 Members | 2,119 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,736 developers. It's quick & easy.

SendEmail with smtp username and password

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
Nov 12 '08 #1
2 7869
This blog has downloadable code.
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

and has a "smarter setter upper" config section for when you need and don't
need extra credentials for emailing.

"Adam Milligan" <Ad**********@discussions.microsoft.comwrote in message
news:07**********************************@microsof t.com...
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

Nov 12 '08 #2
//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);

"Adam Milligan" <Ad**********@discussions.microsoft.comwrote in message
news:07**********************************@microsof t.com...
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
Nov 12 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Pedro | last post: by
4 posts views Thread by Tushar | last post: by
5 posts views Thread by Prashant Barnwal | last post: by
2 posts views Thread by =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post: by
4 posts views Thread by Brian | last post: by
3 posts views Thread by Sajeena | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.