سؤال

Im using the SendGrid API in my Windows Azure environment to send emails. I have a need to alter the email priority (Low\High Importance) of some emails, but I don't see any properties that allow me to do this.

Does anyone have experience with SendGrid who knows how to change the priority? There is a property that allows me to add headers.. so Im not sure if that's something I can use to do this?

Thanks in advance!

هل كانت مفيدة؟

المحلول 2

If you are using the Web API you can use the headers parameter as you mention. If sending via SMTP you can just add the headers to your message.

There are a few headers defined in RFC 4021 that support this as well as some custom ones. I'd use the following JSON for the headers parameter to start:

{“Priority”: “Urgent”, “Importance”: “high”}

If that doesn't work you can also look into the X-Priority and X-MSMail-Priority headers.

نصائح أخرى

I was also looking for a way to mark email as important. After going through a couple of articles, I found the answer over here- https://github.com/sendgrid/sendgrid-csharp/issues/251

All you need to do is add priority in your mail headers. Like this-

mailMessage.Headers.Add("Priority", "Urgent");
mailMessage.Headers.Add("Importance", "high");

Code above works for high priority. I am guessing you would have to do something similar for low priority emails. Hope this helps.

I found that using Headers.Add would throw an Object reference not set to instance of an object error.

Use mailMessage.AddHeader to avoid this.

Found on the same link Pallavi provided. https://github.com/sendgrid/sendgrid-csharp/issues/251

Based on my tests, SmtpClient sets the following headers for high priority:

"X-Priority", "1"
"Priority", "urgent"
"Importance", "high"

And for low priority:

"X-Priority", "5"
"Priority", "non-urgent"
"Importance", "low"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top