如何在.NET应用程序中使用SendGrid V3向多个收件人发送电子邮件 [英] how to send an email using SendGrid V3 to multiple recipients, in a .NET app
问题描述
它发送到一个确定.但不要等于或大于2.我试过用和分隔地址;和to_addr字符串中的空格,但是失败.
It sends to one ok. But not to 2 or more. I've tried separating addresses by , and ; and space in the to_addr string, but failed.
EmailAddress类应针对多种地址使用哪种格式?
What format does class EmailAddress expect for multiple addresses?
public async sub send_message( msg_subject, msg_body, from_addr_text, to_addr_text, optional commands = "")
dim apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY")
dim client as new SendGridClient( apiKey, , , "v3", )
dim from = new EmailAddress( from_addr_text, "INSTRUMENT")
dim subject = msg_subject
if subject = ""
subject = " " ' won't send if empty
End If
dim to_addr = new EmailAddress( to_addr_text, "INSTRUMENT")
dim plainTextContent = msg_body
dim htmlContent = "<strong>" & msg_body & "</strong>"
dim msg = MailHelper.CreateSingleEmail(from, to_addr, subject, plainTextContent, htmlContent)
dim response = await client.SendEmailAsync(msg)
if instr( commands, "SKIP POPUPS") ' TEST TEXT MSG !!!
exit sub
End If
popup_information( "MESSAGE SENDING", "Sent..." & vbcrlf & vbcrlf & "SUBJECT: " & vbcrlf & subject & vbcrlf & vbcrlf & "BODY: " & vbcrlf & msg_body )
end sub
推荐答案
不确定使用的是哪个SDK版本,但是如果您遵循适用于C#的Sendgrid V3 api SDK,则应该在中找到类似以下的方法MailHelper
类
Not sure which SDK version are you using , but if you follow the Sendgrid V3 api SDK for C# , you should find a method like below in the MailHelper
class
public static SendGridMessage CreateSingleEmailToMultipleRecipients(EmailAddress from, List<EmailAddress> tos, string subject,string plainTextContent,string htmlContent)
接受 List< EmailAddress>
的
将电子邮件发送给多个收件人.因此,不要在代码中使用下面的行
which accepts a List<EmailAddress>
to send email to multiple recipients. So instead of using the below line in your code
dim msg = MailHelper.CreateSingleEmail(from, to_addr, subject, plainTextContent, htmlContent)
您应使用以下代码
var to_addr = new List<EmailAddress>();
to_addr.Add(new EmailAddress( to_addr_text, "INSTRUMENT"));
to_addr.Add(new EmailAddress( "secondperson@test.com", "secondperson")); // you can add multiple email in this list
,然后您可以在下面的代码
and then you can use to_addr
in the code below
dim msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, to_addr, subject, plainTextContent, htmlContent)
请以C#示例为例,但同样适用于您的VB.NET代码
Pardon me for the example in C# but the same should be applicable for your VB.NET code
这篇关于如何在.NET应用程序中使用SendGrid V3向多个收件人发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!