2012-12-10 10 views
5

Non riesco a inviare e-mail "sicure" su Sendgrid usando web api. (Piattaforma - .Net/C#, SendgridMail)Impossibile inviare e-mail sicure su Sendgrid usando webapi

Funziona bene con http url (http://sendgrid.com/api/mail.send) ma con https (https://sendgrid.com/api/mail .send) fallisce.

private void SendMail() 
    { 
     var message = SendGrid.GenerateInstance(); 

     //set the message recipients 
     message.AddTo("[email protected]"); 

     //set the sender 
     message.From = new MailAddress("[email protected]"); 

     //set the message body 
     message.Html = "<html><p>Hello</p><p>World</p></html>"; 

     //set the message subject 
     message.Subject = "Hello World HTML Test"; 

     //create an instance of the Web transport mechanism 
     var transportInstance = SendGridMail.Transport.REST.GetInstance(new NetworkCredential("myusername", "mypassword"),"https://sendgrid.com/api/mail.send"); 

     //send the mail 
     transportInstance.Deliver(message); 
    } 

Ottengo un argomentoExclusione: elemento sconosciuto: html.

seguito di perforazione lungo il codice, ricevo questo errore: "400 Bad Request, La richiesta HTTP pianura è stata inviata a porta HTTPS, nginx/0.7.65"

Nota
funziona benissimo con http: url: (http://sendgrid.com/api/mail.send) nella funzione GetInstance sopra invece di (https://sendgrid.com/api/mail.send).

Invio richiesta e-mail attraverso il browser funziona bene: (https://sendgrid.com/api/mail.send.json?to=to%40somedomain.com1 & from = da% 40somdomain.com1 & subject = test% 20SG% 20API & testo = someText & html =% 3CB% 3E% 20Test% 20SG% 20api% 20body & api_user = sendgridusername & api_key = sendgridpassword)

Un aiuto su questo è apprezzato.

+0

Passa a Amazon ses, l'abbiamo fatto, è molto più professionale rispetto a sendgrid e, se sai come configurare correttamente sns, puoi anche ricevere le notifiche. –

+0

Ho aggiornato il pacchetto C# in modo che HTTPS funzioni: https://nuget.org/packages/Sendgrid – bwest

risposta

4

Lavoro per SendGrid. Ho effettuato alcuni test e questa è una limitazione del wrapper C#, in particolare della libreria CodeScales che viene utilizzata per effettuare le chiamate HTTP. CodeScales purtroppo non supporta affatto HTTPS. Ho aperto un problema su GitHub per questo: https://github.com/sendgrid/sendgrid-csharp/issues/21

Inizierò a pianificare il refactoring dell'app per utilizzare RestSharp per effettuare le chiamate API. Scusa per il disturbo!

+1

Le modifiche sono state pubblicate 2 giorni fa per correggere gli errori. – bwest

+0

Grazie mille !!! – user1891155