【发布时间】:2018-03-06 17:40:21
【问题描述】:
我正在使用 Azure Sendgrid 发送电子邮件。如何创建客户端发送电子邮件。它没有 Idisposable 接口。
public async Task<string> SendEmailAsync(string EmailTo, string Username, string Subject, string PlainTextContent, string HtmlContent)
{
string apikey = Configuration.AzureSendgridSecretProvider.ApiKey;
string responseStatus = "BadRequest";
var query = "Email_" + EmailTo + ";" + "Username_" + Username + ";" + "VerficationCode_" + HtmlContent+ ";apikey" + apikey;
var client = new SendGridClient(apikey);
try
{
var msg = new SendGridMessage()
{
From = new EmailAddress(Configuration.AzureTableStorageSendGridProvider.EmailAddress, Configuration.AzureTableStorageSendGridProvider.EmailName),
Subject = Subject,
PlainTextContent = PlainTextContent,
HtmlContent = HtmlContent
};
msg.AddTo(new EmailAddress(EmailTo, Username));
var response = await client.SendEmailAsync(msg);
responseStatus = response.StatusCode.ToString();
}
catch (Exception ex)
{
}
return responseStatus;
}
- 我们可以创建单个客户端来发送所有 SMS(Singleton)
- 发送成功后如何调用 using{} 处理对象?
- 如上调用时是否存在内存泄漏?
【问题讨论】:
-
你是在问它是否有内存泄漏?为什么你认为它必须是
IDisposable? -
我正在使用上面的代码。需要遵循的最佳方法是什么?我必须在我的应用程序中发送并发短信。会好还是不好?