如何在 C# 中使用 sendgrid 添加回复

How to add replyto with sendgrid in C#

我将 sendgrid 与我构建的 .NET Core 站点一起使用。它上面有一个联系表格,因此客户可以填写表格并将其发送到我的电子邮件地址。我正在使用 Sendgrid nuget 包来生成和发送电子邮件。问题是,当我收到电子邮件时,我不想回复自己,当我回复等于输入的电子邮件地址时 - sendgrid 不会发送电子邮件,因为该电子邮件未输入单一发件人验证。必须有一种方法可以在我的电子邮件中进行配置,当我单击回复时,它将转到发送电子邮件的人。对吗?

string key = _iConfig.GetSection("Email").GetSection("SendGridKey").Value;
var client = new SendGridClient(key);

var subject = "Form submission";

var fromemail = _iConfig.GetSection("Email").GetSection("From").Value;
var from = new EmailAddress(fromemail, model.Name);

var toemail = _iConfig.GetSection("Email").GetSection("To").Value;
var to = new EmailAddress(toemail, "Admin");

var htmlContent = "<strong>From: " + model.Name + "<br>Email: " + model.Email + "<br>Message: " + model.Message;
                
var msg = MailHelper.CreateSingleEmail(from, to, subject, model.Message, htmlContent);
var response = await client.SendEmailAsync(msg);
return response.IsSuccessStatusCode;

此处为 Twilio SendGrid 开发人员布道师。

要在 C# 中设置回复地址,您需要 setReplyTo 方法,如下所示:

var msg = MailHelper.CreateSingleEmail(from, to, subject, model.Message, htmlContent);

// Add the reply-to email address here.
var replyTo = new EmailAddress(model.Email, model.Name);
msg.setReplyTo(replyTo);

var response = await client.SendEmailAsync(msg);
return response.IsSuccessStatusCode;