Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active August 16, 2021 21:44
Show Gist options
  • Save aspose-com-kb/4793caec68e29836fc8403c015dc7cfc to your computer and use it in GitHub Desktop.
Save aspose-com-kb/4793caec68e29836fc8403c015dc7cfc to your computer and use it in GitHub Desktop.
Send Mail Using SMTP Server in C#. Send Email Using Gmail SMTP C#. See Details: https://kb.aspose.com/email/net/how-to-send-email-in-c-sharp/
using System;
//Add Aspose.Email for .NET package reference
//Use following namespaces to convert OTG to PDF format
using Aspose.Email;
using Aspose.Email.Clients;
using Aspose.Email.Clients.Smtp;
namespace SendEmailUsingSMTPServer
{
class Program
{
static void Main(string[] args)
{
//Set Aspose license before sending email through Gmail SMTP
//using Aspose.Email for .NET
Aspose.Email.License AsposeEmailLicense = new Aspose.Email.License();
AsposeEmailLicense.SetLicense(@"c:\asposelicense\license.lic");
//create an instance of MailMessage
MailMessage EmailMessage = new MailMessage();
//Set email message properties which you want to specify
EmailMessage.Subject = "How to Send Mail Using SMTP Server in C#";
EmailMessage.To = "ReceiverEmail@EmailServer.com";
EmailMessage.Body = "This is a test of sending email using SMTP in C#.";
//Initiate an instance of SmptpClient class
SmtpClient SMTPEmailClient = new SmtpClient();
//Set SMTP client properties so the email message can get through the server
SMTPEmailClient.Host = "smtp.gmail.com";
SMTPEmailClient.Username = "YourEmail@gmail.com";
SMTPEmailClient.Password = "Your Gamil Password";
SMTPEmailClient.Port = 587;
SMTPEmailClient.SecurityOptions = SecurityOptions.SSLExplicit;
//Finally send the email message using Gmail's SMTP client
SMTPEmailClient.Send(EmailMessage);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment