Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - How to send mail in ASP.NET using C# technology.
Blog
 
# Monday, June 22, 2009
      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 find 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",
                                 "itq@vmaildeliver.vsnl.com");
                //The password used to authenticate to an SMTP server using basic (clear-text) authentication.                 msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","itq.1.123");                 /%                         Specifies 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!!!");             }         }

You can use this above code for sending mail using SMTP in ASP.NET.

Monday, June 22, 2009 11:26:30 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   .Net | asp.net  | 
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: