Sending emails with SendGrid - Local ok , Remote no ok
azure-web-app-service, sendgrid
Solution
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.
Problem
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; } ```