473,409 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

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 7997
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pedro | last post by:
Hi all, a friend using Windows wanted to send mail, but he got timeout errors after editing php.ini Mail section smtp = smtp.server.com sendmail_from = friend@server.com I realized that...
4
by: Tushar | last post by:
Please help: I found some of the following information in messeges in this group but I would like someone to confirm them please. I would like to use the following web-services / ASP.Net code to...
2
by: T.Archer | last post by:
The host a client wants to use requires authentication to relay messages. How do I set the authentication (username/password) before using the smtpmail.send(mailmessage) method? Surely this...
3
by: RN | last post by:
I am tired of sending mail from the built-in SMTP service for so many reasons (errors are nondescriptive in the event log, it doesn't let me control which IP address it sends from, and it...
5
by: Prashant Barnwal | last post by:
Hi, This message i get whne i try to send mails theu my app server. any idea where and what to look for? It works fine in Dev bed. Guide me to apprpriate news group if its not the right place. ...
2
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
I've tried: MailSettingsSectionGroup mailConfig = WebConfigurationManager.GetSection("system.net/mailSettings") as MailSettingsSectionGroup; and: Configuration configurationFile =...
4
by: Brian | last post by:
Hello all, we don't actually host our own server but still should work the same. Here is the error message i get "error mailbox unavailable. The server response was: must be authenticated code...
6
by: phpmagesh | last post by:
Hi, I am using mail function in my php page, As soon i update the details, i have to send mail to the customer with the updated details, problem is when i send mail it simple through waring msg...
3
by: Sajeena | last post by:
I have used smtp mail scripts <?php function authgMail($from, $namefrom, $to, $nameto, $subject, $message) { $smtpServer = "192.168.xxx.xxx"; //ip address of the mail server. This can also be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.