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 » Articles » ASP.NET/Web Applications »

How to send SMTP mail in ASP.NET using C# technology.


Posted Date: 30 Oct 2008    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: shekharMember Level: Gold    
Rating: 1 out of 5Points: 10




Microsoft .net framework provide a facility for sending mail using System.Web.Mail(SMTP) First include this using System.Web.Mail in your code, For sending mail we are creating a function sendMail, it is used for sending email. For correctly running this code, please first register two dll "cdonts.dll" and "cdosys.dll". These two dll is microsoft dll used for sending mail.


public void sendMail()
{
try

{ //Provides properties and methods for sending messages using the
Collaboration Data Objects for Windows 2000 (CDOSYS) message component.

SmtpMail.SmtpServer= "SMTP Server IP Address";

MailMessage msg = new MailMessage();

// Specify the e-mail sender.

msg.From = "rajshekhar@mail.com";//Self mail address

// Set destinations for the e-mail message.

msg.To = "Send Email Address";

// Set destinations of Carbon Copy(CC) for the e-mail message.

msg.Cc = "CC Email Address;

// Set destinations of Blind carbon copies(BCC) for the e-mail message.

msg.Bcc = "BCC Email Address";

// Specify the message subject.

msg.Subject = this.txtSubject.Text;

// Specify the message content.

msg.Body = "Content of Message Assign Here";

msg.BodyFormat = MailFormat.Text;

/*The username for authenticating to an SMTP server using basic (clear-text) authentication.*/

msg.Fields.Add(http://schemas.microsoft.com/cdo/configuration/sendusername, "Your SMTP User Name");

/*The password used to authenticate to an SMTP server using basic (clear-text) authentication. */

msg.Fields.Add(http://schemas.microsoft.com/cdo/configuration/sendpassword, "Password");

/% s pecifies the authentication mechanism to use when authentication is required to send messages to an SMTP service using a TCP/IP network socket.
The Secound parameter in smtpauthenticateis CdoProtocolsAuthentication enumeration, It is used to specify the mechanism used when authenticating to a Simple Mail Transfer Protocol (SMTP) service over the network.

It has three different type of value:

Name Value Description
==== ===== ============

cdoAnonymous 0 Do not authenticate.
cdoBasic 1 Use basic (clear-text) authentication. The
configuration sendusername/sendpassword or
postusername/postpassword fields are used to
specify credentials.
cdoNTLM 2 Use NTLM authentication (Secure Password
Authentication in Microsoft® Outlook® Express)
The current process security context is used
to authenticate with the service.*/

msg.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ,1);

//Sending Message
SmtpMail.Send(msg);
}
catch (Exception ex)
{
ErrorMessage("Send Mail Process was failed!!!");
}
finally
{
SuccessMessage("Send Mail Process was successfull!!!");

}

}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
How to send SMTP mail in ASP.NET using C# technology.  .  

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.
Next Resource: Internationalization(Globalization and Localization) in Asp.Net
Previous Resource: Pop-Up Boxes in JavaScript
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use