SMTP E-Mail are blocked

Mathias Häuser 1 Reputation point
2020-10-23T03:52:45.007+00:00

Hello,

I hosted a Blazor WASM application on Azure. My problem. Sending SMTP based emails e.g. Azure is blocked via the relay sendgrid or directly from a German provider such as Contabo. The emails are sent correctly by the API methods, but Azure does not forward them. What should I do to solve this problem on Blazor WASM in C #?

My ressource: https://boubahnthaimassage.azurewebsites.net/Kontakt

Best regards
Mathias

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,642 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Krish G 2,331 Reputation points
    2020-10-24T04:16:00.407+00:00

    @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);  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.