473,387 Members | 1,892 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,387 software developers and data experts.

How to send a mail using C#

Hi all,

I need to know how to authenticate a user before sending a mail using a
C# application.

The source code i use is this:

private void sendMailButton_Click(object sender, EventArgs e)
{
try
{
MailMessage mailMessage = new
MailMessage(toTextBox.Text, fromTextBox.Text, subjectTextBox.Text,
bodyTextBox.Text);

SmtpClient obj = new SmtpClient(SMTPTextBox.Text);
obj.Send(mailMessage);
MessageBox.Show("Message Sent");

}
catch (Exception ex)
{
MessageBox.Show("message not sent");

}
}

I need to add the authentication part. This is working but with no
authentication for the user or the mail sender address. I am using a
local SMTP server.
Thanks,

Oct 9 '06 #1
1 1407
This is based upon VS2005 and .NET 2.0
You need to set the Credentials property of your SmtpClient to an instance
of a NetworkCredentails object.
SmtpClient obj = new SmtpClient(SMTPTextBox.Text);
! obj.UseDefaultCredentials = False;
! obj.Credentials = new NetworkCredentials( "UserId",
"Password");
! // From here on the SmtpClient should do all your heavy
lifting
obj.Send(mailMessage);
MessageBox.Show("Message Sent");
Chris
"jamilabkh" <ja*******@gmail.comwrote in message
news:11*********************@m7g2000cwm.googlegrou ps.com...
Hi all,

I need to know how to authenticate a user before sending a mail using a
C# application.

The source code i use is this:

private void sendMailButton_Click(object sender, EventArgs e)
{
try
{
MailMessage mailMessage = new
MailMessage(toTextBox.Text, fromTextBox.Text, subjectTextBox.Text,
bodyTextBox.Text);

SmtpClient obj = new SmtpClient(SMTPTextBox.Text);
obj.Send(mailMessage);
MessageBox.Show("Message Sent");

}
catch (Exception ex)
{
MessageBox.Show("message not sent");

}
}

I need to add the authentication part. This is working but with no
authentication for the user or the mail sender address. I am using a
local SMTP server.
Thanks,

Oct 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
6
by: John J. Hughes II | last post by:
I have a service that needs to send e-mail alerts. I have been attempting to use the System.Net.Mail function from .NET but this seems to require the IIS be installed and running. Since some of...
9
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
2
by: Ron | last post by:
hi guys, I am trying to send email using smtpMail. I can send emails inside the organization, but out of the organization I get an error "The server rejected one or more recipient addresses. The...
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...
2
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console...
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
4
by: =?Utf-8?B?dHBhcmtzNjk=?= | last post by:
I have a web page that at the click of a button must send a bunch (1000+) emails. Each email is sent individually. I have the code working fine, using Mail Message classes and smtp and all that. ...
9
by: Mahernoz | last post by:
Can i send an email from JavaScript? Is it possible? If yes please the code to send email using javascript...
7
by: Rob Dob | last post by:
The following code is giving me a timeout problem., no matter what I do I can't send a piece of mail using .net2.0 System.Net.Mail.SmtpClient via port 465 and using ssl, if however I try using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.