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!!!");
}
}
|
No responses found. Be the first to respond and make money from revenue sharing program.
|