简体   繁体   中英

Send schedule emails from sendgrid using c#

I am using SendGrid for sending email in my application . Now i want to send emails to my users on weekly basis . Is there any feature available in sendgrid and if yes then how can i use that api in c#

SendGrid supports scheduled sends of emails with one line of code extra.

Use the SendGridMessage.SendAt property. It expects a UNIX timestamp as a long .

Gets or sets a unix timestamp allowing you to specify when you want your email to be sent from SendGrid. This is not necessary if you want the email to be sent at the time of your API request.

int sendAtUnixTime = new DateTimeOffset(sendOnUtcDateTime).ToUnixTimeSeconds();

var client = new SendGridClient("apiKey");
var from = new EmailAddress("fromEmailAddress", "fromName");
var to = new EmailAddress("toEmailAddress", "toName");
var msg = MailHelper.CreateSingleEmail(from, to, "subject", "", "bodyHtml");
msg.SendAt = sendAtUnixTime;                
var response = await client.SendEmailAsync(msg);

You can build a worker role and defile time to run every week (simple logic). it can read your website database and send the emails to the users you want to mail.

UPD: Sendgrid does support scheduled emails as of v3 API. Please see answer from P.Campbell

Sendgrid does not do scheduled emails.

\n

You'll have to create schedule functionality yourself. I can recommend looking on Azure Scheduler and Scheduled Azure WebJobs . Scheduled WebJobs are working in pair with Azure Scheduler and you can program them to do whatever you need (send emails) on a regular basis (once a week).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM