I have written a program to send a mail from my Gmail account to Yahoo account. The program uses ASP.NET 2.0 and uses SMTP server of Gmail. We have to enable SSL and find out the port number of SMTP of GMAIL, which happens to be 587. But try 465 also. See what what port works for you.As it is a simple program to test a simple mail, i am not taking any input from user. I have used simple body and subject. I have run this and got a mail into my inbox of yahoo.
Just create a new ASP.NET page and place a button on it. Write code for click event of that button. To test it, just run the page and click on the button. If you see no errors, it means message is sent successfully.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
public partial class SendMail : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage m = new MailMessage("get2swarup@gmail.com", "somebody@yahoo.com");
m.Body = "Testing Mail From Gmail.com";
m.IsBodyHtml = false;
m.Subject = "Testing";
m.Priority = MailPriority.High;
// SMPT settings
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); // server name and port number
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential ("get2swarup@gmail.com","password");
smtp.Send(m);
}
}
Regards Swarup.....
Monday, June 9, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment