Articles → AWS → Amazon Simple Email Service In AWS
Amazon Simple Email Service In AWS
Purpose
How To Create SES?
- Verify the email address
- Create SMTP credentials
Verify The Email Address
Create SMTP Credentials
Send An Email Using SES Credentials
using System;
using System.Net;
using System.Net.Mail;
namespace SESDemo
{
class Program
{
static void Main(string[] args)
{
// Replace with your AWS SES SMTP credentials
string smtpUsername = "[User Name]";
string smtpPassword = "[Password]";
// SMTP endpoint for the AWS SES region (e.g., us-east-1)
string host = "email-smtp.ap-south-1.amazonaws.com";
int port = 587; // Port 587 for TLS, or 465 for SSL
// Email details
string from = "admin@gyansangrah.com";
string to = "User@gmail.com";
string subject = "Test Email from AWS SES";
string body = "Hello, this is a test email sent using C# and AWS SES SMTP.";
// Create a new SmtpClient object to send the email
SmtpClient client = new SmtpClient(host, port);
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new NetworkCredential(smtpUsername, smtpPassword);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
// Create the MailMessage object
MailMessage message = new MailMessage(from, to, subject, body);
// Send the email
client.Send(message);
Console.WriteLine("Email sent successfully!");
}
catch (Exception ex)
{
Console.WriteLine("Failed to send email. Error: " + ex.Message);
}
}
}
}