@Mathias Häuser It's recommended to use Sendgrid REST API over SMTP.
Because of the extra “chatter” back and forth during an SMTP connection, we suggest that SendGrid customers use the Web API when possible for several reasons:
- SMTP relay creates multiple points of potential failure, meaning that there are more places in the conversation between the sender and SendGrid that could cause one of those “not okay” messages.
- The Web API is faster. The extra back and forth necessary in SMTP relay can cause some (minimal) latency for customers who are outside of the United States, and thus further from our inbound data centers.
- The Web API also allows you to add an extra layer of security to your program by utilizing API keys. API keys allow you to generate an authentication credential separate from your username password, which significantly lowers the chance of someone using your account to send spam or phish.
Also, there might be whitelisting issue due to outbound SMTP restriction in Azure. If you use REST API instead, you can overcome that.
Here is a C# example using their nuget.
var apiKey = "<send grid api key>";
var client = new SendGridClient(apiKey);
var from = new EmailAddress("test@example.com", "Example User");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress("test@example.com", "Example User");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);