gpt4 book ai didi

email - SendInBlue API (Brevo) 中的参数不起作用。有人面临同样的问题吗?

转载 作者:行者123 更新时间:2023-12-03 07:55:15 27 4
gpt4 key购买 nike

从昨天开始,我一直在尝试通过 SendInBlue API 传递参数,但它不起作用。我已经尝试了一切。我看过很多代码示例,但不幸的是它不起作用。

我什至使用了他们放在网站上的 C# 代码作为示例,但它仍然无法工作。

按照我的代码操作:

using System.Diagnostics;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using sib_api_v3_sdk.Api;
using sib_api_v3_sdk.Client;
using sib_api_v3_sdk.Model;
using Task = System.Threading.Tasks.Task;

namespace cjuridico.Domain.Models.Email;

public static class CadastroEmail
{
public static async Task EnviarEmail(string destinatario, string mensagem)
{
Configuration.Default.AddApiKey("api-key", "<omitted>");
var apiInstance = new TransactionalEmailsApi();
string SenderName = "John Doe";
string SenderEmail = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="36534e575b465a5376534e575b465a531855595b" rel="noreferrer noopener nofollow">[email protected]</a>";
SendSmtpEmailSender Email = new SendSmtpEmailSender(SenderName, SenderEmail);
string ToEmail = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65080411041300090c5c54250208040c094b060a08" rel="noreferrer noopener nofollow">[email protected]</a>";
string ToName = "Guilherme Vianna";
SendSmtpEmailTo smtpEmailTo = new SendSmtpEmailTo(ToEmail, ToName);
List<SendSmtpEmailTo> To = new List<SendSmtpEmailTo>();
To.Add(smtpEmailTo);
string BccName = "Janice Doe";
string BccEmail = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ceabb6afa3bea2abfc8eabb6afa3bea2abfce0ada1a3" rel="noreferrer noopener nofollow">[email protected]</a>";
SendSmtpEmailBcc BccData = new SendSmtpEmailBcc(BccEmail, BccName);
List<SendSmtpEmailBcc> Bcc = new List<SendSmtpEmailBcc>();
Bcc.Add(BccData);
string CcName = "John Doe";
string CcEmail = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c1dcc5c9d4c8c197e4c1dcc5c9d4c8c1968ac7cbc9" rel="noreferrer noopener nofollow">[email protected]</a>";
SendSmtpEmailCc CcData = new SendSmtpEmailCc(CcEmail, CcName);
List<SendSmtpEmailCc> Cc = new List<SendSmtpEmailCc>();
Cc.Add(CcData);
string HtmlContent = "<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>";
string TextContent = null;
string Subject = "My {{params.subject}}";
string ReplyToName = "John Doe";
string ReplyToEmail = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9deff8edf1e4e9f2ddf9f2f0fcf4f3b3fef2f0" rel="noreferrer noopener nofollow">[email protected]</a>";
SendSmtpEmailReplyTo ReplyTo = new SendSmtpEmailReplyTo(ReplyToEmail, ReplyToName);
string AttachmentUrl = null;
string stringInBase64 = "aGVsbG8gdGhpcyBpcyB0ZXN0";
byte[] Content = System.Convert.FromBase64String(stringInBase64);
string AttachmentName = "test.txt";
SendSmtpEmailAttachment AttachmentContent = new SendSmtpEmailAttachment(AttachmentUrl, Content, AttachmentName);
List<SendSmtpEmailAttachment> Attachment = new List<SendSmtpEmailAttachment>();
Attachment.Add(AttachmentContent);
JObject Headers = new JObject();
Headers.Add("Some-Custom-Name", "unique-id-1234");
long? TemplateId = 3;
JObject Params = new JObject();
Params.Add("NOME", "Guilherme");
Params.Add("SENHA", "Guilherme");
List<string> Tags = new List<string>();
Tags.Add("mytag");
SendSmtpEmailTo1 smtpEmailTo1 = new SendSmtpEmailTo1(ToEmail, ToName);
List<SendSmtpEmailTo1> To1 = new List<SendSmtpEmailTo1>();
To1.Add(smtpEmailTo1);
Dictionary<string, object> _parmas = new Dictionary<string, object>();
_parmas.Add("params", Params);
SendSmtpEmailReplyTo1 ReplyTo1 = new SendSmtpEmailReplyTo1(ReplyToEmail, ReplyToName);
SendSmtpEmailMessageVersions messageVersion = new SendSmtpEmailMessageVersions(To1, _parmas, Bcc, Cc, ReplyTo1, Subject);
List<SendSmtpEmailMessageVersions> messageVersiopns = new List<SendSmtpEmailMessageVersions>();
messageVersiopns.Add(messageVersion);
try
{
var sendSmtpEmail = new SendSmtpEmail(Email, To, Bcc, Cc, HtmlContent, TextContent, Subject, ReplyTo, Attachment, Headers, TemplateId, Params, messageVersiopns, Tags);
CreateSmtpEmail result = apiInstance.SendTransacEmail(sendSmtpEmail);
Debug.WriteLine(result.ToJson());
Console.WriteLine(result.ToJson());
Console.ReadLine();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}

最佳答案

我最近在使用 PHP 代码时遇到了同样的问题。最初,我认为这是由于我的代码中的错误造成的。但后来我发现问题出在我的模板上。具体来说,如果您在模板中定义了 {{first_name }},只需将其替换为 {{ params.first_name }},您的电子邮件将开始显示以下值通过 API 调用发送的参数。

关于email - SendInBlue API (Brevo) 中的参数不起作用。有人面临同样的问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76227621/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com