如何在使用 Twilio 验证创建 API 时动态使用来自电子邮件

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

根据 Twilio Sendgrid 文档,发送电子邮件时无法在有效负载中传递发件人电子邮件 ID,共享以下代码以供参考。我只是想知道有什么方法可以在下面的代码中添加发件人电子邮件 ID,同时发送

Email ``channel
的验证链接。

  public HttpResponseMessage VerifyLink(Payload payload)
        {
            
            HttpResponseMessage response = new HttpResponseMessage();
            string accountSid = ConfigurationManager.AppSettings["accSid"]; 
            string authToken = ConfigurationManager.AppSettings["SendGridAut"];             
            var verifyServiceSid = ConfigurationManager.AppSettings["verServiceSid"] ;                                                           
            TwilioClient.Init(accountSid, authToken);            
            try
            {
                // Create verification
                var verification = VerificationResource.Create(
                    to: payload.email,
                    channel: "email",
                    pathServiceSid: verifyServiceSid,
                    channelConfiguration: new
                    {
                        substitutions = new
                        {
                            username = payload.userName,
                            email = payload.email,
                            callback_url = payload.callback_url
                        }
                    }
                );
                var verificationValue = verification;
                response = Request.CreateResponse(HttpStatusCode.OK, "true");
                telemetry.TrackTrace("Verify Email Link Sent Successfully by Createverificationlink API End");
                return response;
            }}

截至目前,我将发件人电子邮件 ID 保留在 Twilio 帐户控制台下的 Twilio 验证服务中,但这不是有用的解决方案,我们需要创建 20 多个不同的电子邮件和同等服务,Twilio 提供了任何内容,以便我们可以添加发件人在发送电子邮件时,在代码部分中发送电子邮件,就像“发送电子邮件”一样。对于我们来说,这些电子邮件需要在发件人身份验证下验证 sendGrid 帐户,这又是一项额外的工作,通常我们可以在从 sendgrid 发送电子邮件时添加任何电子邮件。

我尝试这个代码:-

  public HttpResponseMessage VerifyLink(Payload payload)
        {
            
            HttpResponseMessage response = new HttpResponseMessage();
            string accountSid = ConfigurationManager.AppSettings["accSid"]; 
            string authToken = ConfigurationManager.AppSettings["SendGridAut"];             
            var verifyServiceSid = ConfigurationManager.AppSettings["verServiceSid"] ;                                                           
            TwilioClient.Init(accountSid, authToken);            
            try
            {
                // Create verification
                var verification = VerificationResource.Create(
                    to: payload.email,
                    channel: "email",
                    pathServiceSid: verifyServiceSid,
                    channelConfiguration: new
                    {
                        substitutions = new
                        {
                            username = payload.userName,
                            email = payload.email,
                            callback_url = payload.callback_url
                        }
                    }
                );
                var verificationValue = verification;
                response = Request.CreateResponse(HttpStatusCode.OK, "true");
                telemetry.TrackTrace("Verify Email Link Sent Successfully by Createverificationlink API End");
                return response;
            }}
twilio sendgrid twilio-api
1个回答
0
投票

不,目前无法在代码中指定它。您可以做的是为每个“发件人”配置创建一个验证服务,然后根据您需要的发件人使用不同的服务。

© www.soinside.com 2019 - 2024. All rights reserved.