tencent cloud

Feedback

Sample Call for C#

Last updated: 2024-12-23 14:41:46
Due to the official library's inadequate support for ports 465 and 587, it is recommended to use MailKit, as shown in the following example.
using System;
using MimeKit;
using MailKit.Net.Smtp;
using MailKit.Security;

// This code example uses MailKit (MIT License: https://github.com/jstedfast/MailKit)

class Program
{
static void Main()
{
try
{
// Sender address created in the console
string fromEmail = "test@example.com";
// SMTP password set in the console
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}");
}
}
}

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support