c# - 从 ac# 库返回响应值到 VBA
问题描述
我有一个应用程序,想用它Twilio-SendGrid
来发送一些电子邮件。我查看了他们的 c# 建议,并创建了一个DLL/COM
可以正常工作的基本文件,但除了他们的示例之外,我还想返回"StatusCode"
应用Access
程序。
我需要确定我正在使用的建议的静态变量方法是否是一种好方法,或者我是否应该使用不同的方法。
using System.Threading.Tasks;
using SendGrid;
using SendGrid.Helpers.Mail;
namespace TSLib_SendGrid
{
public class SendGrid
{
public static string strResponse = "";
public string SendNow(string apiKey)
{
Execute(apiKey).Wait();
return strResponse;
}
static async Task<string> Execute(string apiKey)
{
var client = new SendGridClient(apiKey);
var from = new EmailAddress("abc@123.com", "From user");
var to = new EmailAddress("xyz@987.com", "To recipient");
var subject = "Sending with SendGrid is Fun";
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);
strResponse = response.StatusCode.ToString();
return strResponse;
}
}
}