[英]Serialize SendGridMessage object
I am building a system that need to send some transactional mails, and to achieve this I am using Azure storage queues to store the message temporarily before it is picked up by a WebJob and sent off to the intended recipient. 我正在构建一个需要发送一些事务性邮件的系统,并且要实现此目的,我正在使用Azure存储队列临时存储该消息,然后再由WebJob将该消息发送给预期的收件人。
My Code is as follows: 我的代码如下:
SendGridMessage message = new SendGridMessage();
//Populate message with details - omitted for brevity
var serializer = new JavaScriptSerializer();
var modelAsString = serializer.Serialize(message);
try
{
var setting = CloudConfigurationManager.GetSetting("AzureStorageConnectionString");
var account = CloudStorageAccount.Parse(setting);
var queueClient = account.CreateCloudQueueClient();
var queue = queueClient.GetQueueReference("FSPortalEmailQueue");
queue.CreateIfNotExists();
queue.AddMessage(new CloudQueueMessage(modelAsString));
}
catch (Exception ex)
{
//Something went wrong
}
Each time I try to execute the coder, an exception is thrown on the 每次我尝试执行编码器时,都会在
var modelAsString = serializer.Serialize(message);
var modelAsString = serializer.Serialize(message);
"Exception has been thrown by the target of an invocation."
“调用的目标已引发异常。”
The inner exception thrown was 引发的内部异常是
{"Bad key path!"} from source "SendGrid.SmtpApi"
来自“ SendGrid.SmtpApi”来源的{“ Bad key path!”}
Please advise what I am doing wrong here. 请在这里告诉我我在做什么错。
After a bit more digging, it turns out that the message.header node was not being initialised. 经过更多的挖掘后,结果发现未初始化message.header节点。 After adding
添加后
message.Header = new SendGrid.SmtpApi.Header();
message.Header.SetTo(new List<String> { enquiry.EnquiryCreatedBy.Email });
all started working pretty magically 所有人都开始神奇地工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.