using System;
using MimeKit;
using MailKit.Net.Smtp;
using MailKit.Security;
class Program
{
static void Main()
{
try
{
string fromEmail = "test@example.com";
string password = "your password";
string toEmail = "to@example.com";
string smtpHost = "sg-smtp.qcloudmail.com";
int smtpPort = 465;
var message = new MimeMessage();
message.From.Add(new MailboxAddress("", fromEmail));
message.To.Add(new MailboxAddress("", toEmail));
message.Subject = "Test Email with HTML Content";
message.Body = new TextPart("html")
{
Text = @"
<html>
<body>
<h1 style='color:blue;'>Hello!</h1>
<p>This is a <b>HTML test email</b> from <i>Tencent Cloud SES</i>.</p>
<p>Visit <a href='https://www.tencentcloud.com/'>this link</a> for more info.</p>
</body>
</html>"
};
using (var client = new SmtpClient())
{
client.Connect(smtpHost, smtpPort, SecureSocketOptions.SslOnConnect);
client.Authenticate(fromEmail, password);
client.Send(message);
client.Disconnect(true);
}
Console.WriteLine("Email sent successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
Was this page helpful?