Monday, 1 July 2013

How to send Mail to the other User In asp.Net



Description:-


               In this Example we explain that how to send email to the user using simple code are defined as below.

we provide same facility of Email as provide in Gmail you can easily send the Email to any user.

   Explanation:-
                         mail.From = new MailAddress(Reciever EmailId);
               mail.To.Add(Reciever EmailId);

             this two above line Define that Reciever EmailId.
means 
                         mail.From = new MailAddress("abhay.makadia@gmail.com");
               mail.To.Add("abhay.makadia@gmail.com");


 SmtpServer.Credentials = new System.Net.NetworkCredential("username@id","password");

             this line defined the Sender UserId or Password means your Gmail Account username and password.

there is some setting Required Before sendind Mail to user here is a step How to Send Email like

step 1:- Go to Website and click on asp.net website Configuration in visual studio like


Step 2:- click on Application and then After click on Smtp Email Configuration Link



Step 3:- Fill up the Information in Form Like emailid password port and server.

Servername=smtp.gmail.com
port=25
from=your email
sender username=your email
senderpassword=your gmail password




To send SMS in Asp.Net to any User then click Here Send SMS or message in Asp.net

create Paging or Custom paging in DataList Paging in datalist


 To send Email with Attechment File click Here Send Email with Atteched File in Asp.Net

Read and Write File in asp.Net Read/Write File in Asp.Net with C#



Example:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class sendmail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
     

        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
        mail.From = new MailAddress("abhay.makadia@gmail.com");
        mail.To.Add("abhay.makadia@gmail.com");
        mail.Subject = "Forgot Password Mail";
        mail.Body = "click here";
        mail.IsBodyHtml = true;
        SmtpServer.Port = 25;
        SmtpServer.Credentials = new System.Net.NetworkCredential("username@id","password");
        SmtpServer.EnableSsl = true;
        SmtpServer.Send(mail);
        Label1.Text = "Please open your email id Account then check the password...!!!";
    }

}

1 comments:

  1. {System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.68.108:25
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
    --- End of inner exception stack trace ---
    at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
    at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)
    at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
    at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
    at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
    at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
    at System.Net.Mail.SmtpClient.GetConnection()
    at System.Net.Mail.SmtpClient.Send(MailMessage message)
    --- End of inner exception stack trace ---
    at System.Net.Mail.SmtpClient.Send(MailMessage message)


    error while using above code

    ReplyDelete