Asp.net 中的 Mandrill 集成
Mandrill Integration in Asp.net
我想通过 Mandrill 发送电子邮件。如何在 .Net 中执行此操作?
有没有示例代码?
谢谢
您可以像 https://github.com/shawnmclean/Mandrill-dotnet 那样使用 .Net 的包装器。安装库:Install-Package Mandrill
然后做这样的事情:
MandrillApi api = new MandrillApi(MandrillKey);
// Set email or list of emails
var listEmails = new List<EmailAddress>() { new EmailAddress("email@example.com", "User name", "to")};
// Build email to be sent
EmailMessage emailMessage = new EmailMessage()
{
To = listEmails,
FromEmail = FromEmail,
FromName = FromName,
Subject = "Subject of email",
Text = "Message of email",
};
// Creates messsage request based on email messasge
SendMessageRequest emailRequest = new SendMessageRequest(emailMessage);
// Get email results
List<EmailResult> emailResult = await api.SendMessage(emailRequest);
// Loop results
foreach (var emailRes in emailResult)
{
if (emailRes.Status == EmailResultStatus.Sent)
{
// email sent
}
else
{
// email not sent
}
}
我想通过 Mandrill 发送电子邮件。如何在 .Net 中执行此操作?
有没有示例代码?
谢谢
您可以像 https://github.com/shawnmclean/Mandrill-dotnet 那样使用 .Net 的包装器。安装库:Install-Package Mandrill
然后做这样的事情:
MandrillApi api = new MandrillApi(MandrillKey);
// Set email or list of emails
var listEmails = new List<EmailAddress>() { new EmailAddress("email@example.com", "User name", "to")};
// Build email to be sent
EmailMessage emailMessage = new EmailMessage()
{
To = listEmails,
FromEmail = FromEmail,
FromName = FromName,
Subject = "Subject of email",
Text = "Message of email",
};
// Creates messsage request based on email messasge
SendMessageRequest emailRequest = new SendMessageRequest(emailMessage);
// Get email results
List<EmailResult> emailResult = await api.SendMessage(emailRequest);
// Loop results
foreach (var emailRes in emailResult)
{
if (emailRes.Status == EmailResultStatus.Sent)
{
// email sent
}
else
{
// email not sent
}
}