Click here to Skip to main content
15,896,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;// for backgroundworker class
using System.Net;
using System.Net.Mail;

using System.Threading;

namespace ProLogixPOS
{
    public partial class frmForgetPassword : System.Web.UI.Page
    {
        BackgroundWorker bw;
        public void SendMail()
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("ham4159@gmail.com");
            msg.To.Add("aaj_4159@yahoo.com");
            msg.Body = "Testing the automatic mail";
            msg.IsBodyHtml = true;
            msg.Subject = "Movie Data";
            SmtpClient smt = new SmtpClient("smtp.gmail.com");

            smt.Port = 25;
            smt.Credentials = new NetworkCredential("ham4159@gmail.com", "123456789");
            smt.EnableSsl = true;
            smt.UseDefaultCredentials = true;
            smt.Send(msg);
            string script = "<script>alert('Mail Sent Successfully');self.close();</script>";
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "sendMail", script);
        }
       
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SendMail();
          }
    }
}
Posted
Updated 4-Oct-14 6:19am
v2
Comments
[no name] 4-Oct-14 11:40am    
Just dumping a bunch of unformatted code here is not a question. Do some research for the gmail settings. The port for gmail is not 25.
[no name] 4-Oct-14 11:47am    
Searched now for one Minute for the question mark. I don't find the pb. Sorry :(

And unfortunately my Status does not allow me to format your code :(

Pls improve your question, select the code and then _mark_ it as code
Dilan Shaminda 4-Oct-14 12:21pm    
are you getting any exceptions?

You are doing it wrong.

Refer my previous answer sending email to gmail from asp.net[^].

You will get the full working code.
 
Share this answer
 
v2
Hi, since you're using old methods of C# that people don't use anymore in ASP.NET, you need to update the code, and use the ASP.NET version of the code.

I have written an article, about sending emails in ASP.NET and it focuses the Gmail accounts.

Sending Emails Easily Using ASP.NET Helpers[^]

The major part, is the port number you're connecting through, and that the connection would be secure, in ASP.NET you do that using

C#
WebMail.EnablSsl = true;


..then you continue. Read the article, it has the working code sample. You can test it too, and also it has some explaination of the basic concepts of sending the emails in ASP.NET using gmail accounts.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900