Simplest Way of Sending Email from Gmail
protected void btnSendEmail_Click(object sender, EventArgs e)
{
//Create Mail Message Object with content that you want to send with mail.
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("dotnetguts@gmail.com","myfriend@yahoo.com",
"This is the mail subject", "Just wanted to say Hello");
MyMailMessage.IsBodyHtml = false;
//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential("dotnetguts@gmail.com", "myPassword");
//Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
//For different server like yahoo this details changes and you can
//get it from respective server.
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com",587);
//Enable SSL
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(MyMailMessage);
}
39 comments:
When i use your code i found following error 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
Worked so well :)
worked very well for me tooo... thnx for providing the code
nktonu@yahoo.com
This worked very well for me. Like a charm.
thanks it really helped me
i got error "The operation has timed out" when i m executing. Plz help me
Thanks for code, it works flawlessly.
But i tried it for yahoo and not found any luck here.
Will you please direct me to do it
Nice. Helped me with that port.. Thought it was 465.
Thank you! )
Hey This is veryyyyy helpful to me.
Thank you.
(So i can done my hw now. phewww.)
When I used your comment I got the folloing error Message.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Can you please guid me How to rectify this
@Sakthivel
I have tested the code and it is working perfectly fine.
Make sure that you haven't forget adding following lines.
//Enable SSL
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
Also change Email and Password, Incase if you are not changing it.
This worked well!
Thanks for the code.
Download Free Photos
Yeeah maaan!
It worked YEEESSS. AAAAaaaaa!! :)))
I spend a 9-8 hours trying to figure out this thing!
THANK YOU VERY-VERY Much!
Hugs& Kisses :))
:)))
Just kidding :))
Its work but its return DeliveryNotification value is fail
but i have received mail
have u any idea about this one
No error, worked very cool ! Thanks for sharing.
Hey Thanks Buddy it is perfect
now what i want is need is CC and BCC
great man great It's working so good THanks again
Hey cool its workin!!! Thanks 4 code yaa.. :):)
Really usefull, thanks a lot, it works fine :)
Does anyone know the maximum number of emails i can send per day ?
I read in other pages that there is a limit to the number of emails, but none give me the exact number.
Thanks
@Wael
I don't know the exact number too, but there is a limit of I guess 50 emails per hour. This limit is to avoid Spamming of email.
Dear Sir,
I hope you are doing well. I got this email address from one of your contribution web site. I have launched a web site www.codegain.com and it is basically aimed C#,JAVA,VB.NET,ASP.NET,AJAX,Sql Server,Oracle,WPF,WCF and etc resources, programming help, articles, code snippet, video demonstrations and problems solving support. I would like to invite you as an author and a supporter.
Looking forward to hearing from you and hope you will join with us soon.
Thanks so much!!! I spent ages trying to figure this out. Had the wrong port number.
thank you so much sir...
thank you so much sir...
thank you so much sir...
thank you so much sir...
thank you so much sir...
thank you so much sir...
thank you so much sir...
thank you so much sir...
thank you so much sir...
thank you so much sir...
Your Code is very much useful...
Wow.. amazing. It worked. I was struggling since 2 days to make it work.
it worked at least!!!, thxxx!!
Excellent code, thank-you very much
thank you ,it really worked
strugling from 2 days ,trying lots of things that dint work,thank you once again
This help me out. Thank you very much
Awesome man!
Thanks a lot sir ur code is working perfectly
thanks
thanks
thanks
thanks
thanks
thanks
thanks
thanks
thankst
hanks
Thank you very much sir
it helped me in completing my project lot.........
thanks buddy really thank u very much
i can get the from email from the form textbox and it defaults to the smtp account email i am sending it from
Thank U Very much
GOt an error like this: SmtpException was unhandled by user code in the last line of the form mailClient.Send(MyMailMessage);
please reply me.....
Thanks in advance :)
@krish - SmtpException is very generalize statement, can you plz add more details? As per your comment, I would say try to see whether "MyMailMessage" is defined correctly.
Post a Comment