Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending emails with SendGrid - Local ok , Remote no ok [closed]

Sending emails with SendGrid

Works just fine on my local (code below) No source control, just a straight WebDeploy of the same code to AzureWebsites yeilds the error below. SendGrid support have no clue.

Exception Details: System.Net.Sockets.SocketException:

[SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions]

CodeScales.Http.HttpClient.Navigate(HttpRequest request, HttpBehavior httpBehavior) +772 CodeScales.Http.HttpClient.Execute(HttpRequest request) +45 SendGridMail.Transport.REST.Deliver(ISendGrid message) +115

public bool SendEmail(string from, string to, string subject, string content)
  {
       var myMessage = SendGrid.GenerateInstance();
       // Setup the email properties.
       myMessage.From = new MailAddress(from);
       myMessage.AddTo(to);
       myMessage.Text = content;
       myMessage.Subject = subject;

       var username = "#####";
       var pswd = "#####";
        var credentials = new NetworkCredential(username, pswd);
        // Get REST instance for sending email.
        var transportREST = REST.GetInstance(credentials);

        // Send the email.
        transportREST.Deliver(myMessage);

        return true;
    }
like image 838
user1748217 Avatar asked Oct 15 '12 20:10

user1748217


People also ask

How to send emails with SendGrid?

You can use the SendGrid APIs and SDKs to start sending emails within minutes. You could also use the SMTP protocol if you already have an existing codebase that relies on SMTP. In this post, you will learn how to send emails using the SendGrid .NET SDK and a .NET 6 console application.

What does the HTTP status code mean in the SendGrid API?

When the SendGrid API responds with a successful HTTP status code, that does not necessarily mean that the email was successfully received by the recipient. It does however mean that the SendGrid API has accepted your request and will send the email. If the recipient does not receive the email, you can use the Email Activity Feed to find out why.

Why is my email being blocked by Sendgrid?

If a from header is not included, SendGrid will block your email because it doesn’t follow RFC 5322 compliance guidelines. Note that the name should be wrapped in quotation marks, and the address should be wrapped in a greater than and less than symbol. Include a subject line and press Enter.

What is Twilio SendGrid and how does it work?

Twilio SendGrid helps you send and receive emails at scale. You verified your email address as a single sender to send emails from. You used the default host builder to set up flexible configuration and extensible dependency injection. Using what you learned here, you can also start integrating SendGrid into your ASP.NET Core applications.


1 Answers

This looks like some sort of Windows Azure bug rather than a SendGrid issue. My two recommendations for fixing this are:

1. Try using the SMTP API instead of the web API to send the email

It could be that there's something wrong with outbound HTTP connections (this would really surprise me, but hey, it happens).

2. Try using the code that Azure provides

Azure has pretty good docs on how to use SendGrid, it might be worth taking a look at those and using some of their sample code.

http://www.windowsazure.com/en-us/develop/net/how-to-guides/sendgrid-email-service/

3. Contact Azure support

They can look under the hood and see what it is that you're doing to cause the error. If you do this, make sure you post back what they say here.

like image 186
Swift Avatar answered Oct 04 '22 10:10

Swift