【问题标题】:How to add replyto with sendgrid in C#如何在 C# 中使用 sendgrid 添加回复
【发布时间】:2021-10-27 20:00:47
【问题描述】:

我将 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;

【问题讨论】:

    标签: c# sendgrid reply


    【解决方案1】:

    这里是 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多