This article explains the steps to send email from gmail using c#. Sometimes you don’t want to rely on your host to send emails. What if you want to send an email using gmail account? Sending an email in C# is a very simple task and it would not take much time to implement the functionality in C#.net.
|Send email from Gmail using C#.Net|
In last article we learned to send an email in asp.net using C#. That article is very generic and only need to change the smtp server address, sender email id and password.
How to send email from gmail using c#
In this c# tutorial we are going to learn to send email from gmail using C#. Sending an email from C# is never been a big task. Please look at below code. Below given SendEmail is a method that accepts Recipients email id, subject of an email and body of an email. Call this method wherever required with passing three parameter values. Mostly you would like to call this method on send button. The most important thing is that you can place and call this method in any web application to send email in asp.net or winforms application or wpf applications.
You can use above method to send an email from gmail using c#. But what particular settings we used for gmail in above code? Below are the settings that you need to use –
- Smtp server address – smtp.gmail.com
- Port – 587 or 465
- EnableSsl – true
Gmail always uses SSL/TLS authentication, hence you need to enable the SSL property on port 587 or 465 to send email in c#. As given above, the smtp address of the gmail is “smtp.gmail.com“. The highlighted part on above code shows the SenderEmailID and password. You just need to replace them with your gmail id and password to send email using c#.
To get more insights on how to code, please read how to send an email in Asp.net using C#.
In this c# tutorial we learned send email from gmail using c#. I hope you enjoyed the article. If you find this article helpful, then could you please share the article on your social media?
More articles –