Groups | Blog | Home
all groups > c# > october 2006 >

c# : How to send a mail using C#


jamilabkh
10/8/2006 11:49:56 PM
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,
Forrest
10/9/2006 12:00:00 AM

Uzytkownik "jamilabkh" <jamilabkh@gmail.com> napisal w wiadomosci
news:1160376596.015499.226840@c28g2000cwb.googlegroups.com...
[quoted text, click to view]

At first you must using System.Net namespace and then you can put this
sample code in your app
SmtpClient smtp = new SmtpClient("smtpNameServer", port);

smtp.Credentials = new NetworkCredential(user, password);

Forrest

AddThis Social Bookmark Button