I have an application and want to use Twilio-SendGrid
to send out some emails. I have looked a their c# suggestion, and created a basic DLL/COM
file which works fine, but in addition to their example, I also want to return the "StatusCode"
back to the Access
application.
I need to establish, if the proposed static variable approach that I am using is a good way to go, or if I should use a different method.
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;
}
}
}