www.allfree-stuff.com


Monday, April 5, 2010

Sending Email from ASP.NET (C# or CSharp and VB) webpage using your Gmail email account.

C#/CShapr CODE
using System.Net.Mail;


MailMessage mail = new MailMessage();
mail.To.Add("toEmail@gmail.com");
mail.From = new MailAddress("fromEmail@gmail.com");
mail.Subject = "Subject of Email" ;

string Body = "This is a body of Email";
mail.Body = Body ;
mail.IsBodyHtml = true ;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("fromEmail@gmail.com", "yourPassword");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
try
{
smtp.Send(mail);
Label1.Text = "eMail Send OK... ";
}
catch (Exception ex)
{
Label1.Text = "Error Sending eMail: " + ex.Message.ToString();
}

--------------------
VB Code

Imports System.Net.Mail

Dim mail As New MailMessage
mail.To.Add("toEmail@gmail.com")
mail.From = New MailAddress("fromEmail@gmail.com")
mail.Subject = "Subject of Email"
Dim body As String
body = "This is a body of Email"
mail.Body = body
mail.IsBodyHtml = True
Dim smtp As New SmtpClient
smtp.Host = "smtp.gmail.com" ' //Or Your SMTP Server Address
smtp.Credentials = New System.Net.NetworkCredential _
("yourEmail@gmail.com", "yourPassword")
'Or your Smtp Email ID and Password
smtp.EnableSsl = True
Try
smtp.Send(mail)
Label1.Text = "eMail Send OK... "
Catch ex As Exception
Label1.Text = "Error Sending eMail: " + ex.Message
End Try

14 comments:

妍妮妍妮 said...

how do u do?................................................................

羅惠玲 said...

Of two evils choose the least.......................................................

1hose韻如ak09r_cruickshan said...

Nice Post~!!!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ElroyDockins03 said...

很高興見到你哦!!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

巧生 said...

It's great!!..........................................

黃k0822oryb_card said...

人生是故事的創造與遺忘。...............................................................

B120ryantScipio1 said...

上來打聲招呼,祝你一切平安!.............................................

韋于倫成 said...

A good medicine tastes bitter. ........................................

冠中 said...

每一個人無論怎樣渺小,在自己的眼中,都自有其份量 ..................................................

子帆 said...

生存乃是不斷地在內心與靈魂交戰;寫作是坐著審判自己。...........................................................................

josema said...

金銀愈加磨鍊,愈加光亮,人生愈加考驗,生命愈加光輝。 ............................................................

jackveronic said...

這一生中有多少人擦肩而過?而朋友是多麼可貴啊! ............................................................

育財 said...

nice job! waiting for your new artical. .................................................................

世禾 said...

果然很有意思呀....這當然要頂一頂呀.................................................................