Showing posts with label ASP.Net Send mail using yahoo SMTP. Show all posts
Showing posts with label ASP.Net Send mail using yahoo SMTP. Show all posts

Sunday, February 19, 2012

Send mail using Yahoo SMTP server using ASP.Net


This program will send mail from your yahoo SMTP server. Change username and password of the following code and use your yahoo username and password.



Step 1) Download the EASendMail package for send mail. Trial version is freely available. But it will not work after one month. Here is the following link to download package.


Step 2)Unzip the file and add EASendMail20.dll file if you use .net framework 2. otherwise choose .dll file depending upon your .net framework


Step 3) Add following code in your ASP.Net page.And put your yahoo username and password
 
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Generic;
using EASendMail; //add EASendMail namespace

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
       
            SmtpMail oMail = new SmtpMail("TryIt");
            SmtpClient oSmtp = new SmtpClient();

            // Your yahoo email address
            oMail.From = "sourav.kayal@yahoo.com";

            // Set recipient email address
            oMail.To = "sourav.kayal@yahoo.com";

            // Set email subject
            oMail.Subject = "test email from yahoo account";

            // Set email body
            oMail.TextBody = "this is a test email sent from c# project with yahoo.";

            // Yahoo SMTP server address
            SmtpServer oServer = new SmtpServer("smtp.mail.yahoo.com");

            // For example: your email is "myid@yahoo.com", then the user should be "myid@yahoo.com"
            oServer.User = "senduser@yahoo.com";
            oServer.Password = "password";

            // Because yahoo deploys SMTP server on 465 port with direct SSL connection.
            // So we should change the port to 465.
            oServer.Port = 465;

            // detect SSL type automatically
            oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

            try
            {
                Response.Write("start to send email over SSL ...");
                oSmtp.SendMail(oServer, oMail);
                Response.Write("Email was sent successfully!");
            }
            catch (Exception ep)
            {
                Response.Write("failed to send email with the following error:");
                Response.Write(ep.Message);
            }
        


    }
}