Tuesday 18 February 2014

send mail(simple) in asp.net

if you want to send simple mail in asp.net using c# code then  do following

--> first import two namespace in code behind file(C # code file)
------------------------------------------------------------------------------------------------

using System.Net;
using System.Net.Mail;

--->next write following function in your code behind file
------------------------------------------------------------------------------------------------

 void SendMail()
    {
        String Subject, From, Recipients, Body, smtpHost, port;
        smtpHost = "0.0.0.0";   // Your IP  address
        port = "25";
        From = "abc@xyz.com";   //From : address which account to you send mail
        Recipients = abc123@yahoo.com;  // To : address where you send mail
        Subject = "send mail"; //  Your subject which is appear in recipients inbox
        Body = "";  //Your mail body your message
        MailMessage mailObj = new MailMessage(From, Recipients, Subject, Body);
        SmtpClient smtpClient = new SmtpClient(smtpHost, Convert.ToInt32(port));
        smtpClient.Credentials = new System.Net.NetworkCredential("abc@xyz.com", "abcxyz");
         //above line set Your Mail id and password
        smtpClient.Send(mailObj);
    }

--> this function use where you want to send Mail

No comments:

Post a Comment



Asp.net tutorials