C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Email »

Sending eMail using SmtpClient class


Posted Date: 23 Feb 2007    Resource Type: Code Snippets    Category: Email
Author: kumarMember Level: Diamond    
Rating: 1 out of 5Points: 10



This sample code demonstrates how to send an email using the System.Net.Mail.SmtpClient class.


private bool sendMail(string strToAddress, string strFromAddress, string strSubject, string strBody)
{
// new instance of MailMessage
MailMessage mailMessage = new MailMessage();

// Sender Address
mailMessage.From = new MailAddress(strFromAddress);

// Recepient Address
mailMessage.To.Add(new MailAddress(strToAddress));

// Subject
mailMessage.Subject = strSubject;

// Body
mailMessage.Body = strBody;

// format of mail message
mailMessage.IsBodyHtml = true;

// new instance of Smtpclient
SmtpClient mailSmtpClient = new SmtpClient("smtpServer");

// mail sent
mailSmtpClient.Send(mailMessage);
}



Responses

Author: gokul    12 May 2008Member Level: Silver   Points : 2
NIce example dude


Author: santhoshkumar    12 May 2008Member Level: Gold   Points : 2
Good kumar.


Author: gokul    12 May 2008Member Level: Silver   Points : 2
NIce example dude


Author: Pandya Markand V    16 Jul 2008Member Level: Bronze   Points : 2
i used this code, but its not working.
at the end at send(mailMessage), it shows error like
"Sending Faiure"...
i'm usnig my 2 email accounts to send n receive.

plzzz give me some suggetion, how can i send mail from my
website.

i'm making website which contains a form.
user will fill his email id in it and when he/she
click on submit, one mail should be sent to that person
on my name/id as a sender.

hoping 4 fast rly...
thanking u.
markand pandya


Author: Curve Technologies    06 Sep 2008Member Level: Bronze   Points : 2
you need to define the smtp server to send an email that can be defined in the web.config. it can be as follows:-












-----
You can also refer to a similar kind of example at the following url:- http://forums.asp.net/t/971802.aspx

Hope this helps and resolve your problem.

Thanks..


Author: Junaid Soomro    09 Nov 2008Member Level: Bronze   Points : 1
I need complete file with code which I upload in my web and the Form will working. please upload in zip. thanks.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Its really good  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Previous Resource: Send email with embedded images
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use