有没有办法使用sendgrid库添加ReplyTo?
我使用以下代码,但它不起作用:
SendGridMessage myMessage= new SendGridMessage();
myMessage.AddTo(toEmail);
myMessage.From = new MailAddress("", "");
myMessage.Subject = subject;
myMessage.Html = body;
MailAddress rpto = new MailAddress("test@test.com");
**//This not works**
myMessage.ReplyTo = rpto;
var credentials = new NetworkCredential("", "");
var transportWeb = new Web(credentials);
transportWeb.DeliverAsync(myMessage);
错误: 无法隐式转换类型&System; Net.Mail.MailAddress'到' System.Net.Mail.MailAddress []'
我在https://github.com/sendgrid/sendgrid-csharp/issues/58找到的搜索未实现。
有关此问题的任何解决方法吗?
答案 0 :(得分:0)
看起来ReplyTo
期待一个数组而你只提供一个地址。
尝试做:
MailAddress rpto = new MailAddress("test@test.com");
var addresses = new [] { rpto };
myMessage.ReplyTo = addresses;
但是如果ReplyTo
已过时,只需使用ReplyToList
并提供它所要求的内容即可。如果是列表,只需创建一个包含单个元素的列表。
MailAddress rpto = new MailAddress("test@test.com");
var addresses = new List<MailAddress>();
addresses.Add(rpto);
myMessage.ReplyToList(addresses);