我可以使用C#和Amazon SES API罚款发送电子邮件。但是,出于各种原因,我想在每封HTML电子邮件中都包含纯文本版本。
我找不到如何使用Amazon SES在C#中将纯文本版本添加到HTML电子邮件的任何示例。这可能吗?
这是我用来发送不带纯文本版本的HTML电子邮件的代码:
private string SendEmailHTMLViaAmazonSESAPI(string fromName, string fromEmail, string toEmail, string subject, string body)
{
try
{
if (toEmail.Length > 5)
{
using (IAmazonSimpleEmailService client = new AmazonSimpleEmailServiceClient(RegionEndpoint.EUWest1))
{
var sendRequest = new SendEmailRequest
{
Source = fromName + "<" + fromEmail + ">",
Destination = new Destination { ToAddresses = new List<string> { toEmail } },
Message = new Message
{
Subject = new Content(subject),
Body = new Body { Html = new Content(body) }
}
};
// Send email using AWS SES
SendEmailResponse response = client.SendEmail(sendRequest);
return "Email Sent";
}
}
else
{
return "Error: Invalid Email";
}
}
catch (Exception ex)
{
return "Error: " + ex.Message;
}
}