无法将类型“System.Net.Mail.MailAddress”隐式转换为“SendGrid.Helpers.Mail.EmailAddress”

问题描述 投票:0回答:2

我正在尝试发送电子邮件并收到此错误

无法将类型“System.Net.Mail.MailAddress”隐式转换为“SendGrid.Helpers.Mail.EmailAddress”

    var myMessage = new SendGridMessage();
        myMessage.AddTo(message.Destination);
        myMessage.From = new MailAddress("[email protected]", "My name");//here the error Happens
        myMessage.Subject = message.Subject;
        myMessage.PlainTextContent = message.Body;
        myMessage.HtmlContent= message.Body;
c# email
2个回答
8
投票

您刚刚犯了一个小错字。

改变

myMessage.From = new MailAddress("[email protected]", "My name")

myMessage.From = new EmailAddress("[email protected]", "My name")
                     ^

-1
投票

发送网格错误:

无法从“System.Net.Mail.MailAddress”转换为 '字符串'WindowsServiceCG

添加方法

EmailAddress
而不是
MailAddress

SendGridMessage message = new SendGridMessage();
message.AddBcc(new EmailAddress("Your Email Address", "personalization msg"));
© www.soinside.com 2019 - 2024. All rights reserved.