2015-07-21 64 views
0
private async void sendMail(string from,string to, string subject,string text) 
    {  
     // Create network credentials to access your SendGrid account 
     string username = "xx"; 
     string pswd = "xx"; 

     MailMessage msg = new MailMessage(); 

     NetworkCredential credentials = new NetworkCredential(username, pswd); 
     // Create the email object first, then add the properties. 
     // Create the email object first, then add the properties. 
     SendGridMessage myMessage = new SendGridMessage(); 
     myMessage.AddTo("xx"); 
     myMessage.Subject = "Testing the SendGrid Library"; 
     myMessage.Text = "Hello World!"; 
     myMessage.From = new MailAddress(from); 

     // Create an Web transport for sending email. 
     var transportWeb = new SendGrid.Web(credentials); 

     // Send the email. 

     await transportWeb.DeliverAsync(myMessage); 
    } 

我的應用程序的Windows Phone 8.1,我嘗試通過sendGrid發送郵件我創建了一個帳戶,包括庫代碼,但它提供了3錯誤:的Windows Phone 8 sendGridMessage編譯錯誤

  1. 錯誤CS0570: 「SendGrid.SendGridMessage.From」不被支持的語言
  2. 錯誤CS1502:爲「SendGrid.Web.Web(串)」的最佳重載的方法匹配具有一些無效參數
  3. 錯誤CS1503:參數1:不能轉換從'System.Net.NetworkCredential'到'string'

我已經使用這個網站「https://azure.microsoft.com/tr-tr/documentation/articles/sendgrid-dotnet-how-to-send-email/」作爲參考。

錯誤源於因爲應用程序是Windows Phone應用程序還是什麼?

是否有任何其他方式通過在代碼中聲明「from」來發送電子郵件?

回答

1

這不是你的問題的真正答案,但它足夠重要,我將它作爲答案而不是評論。

這不是從移動設備發送電子郵件的安全方式,因爲您將包含憑證的代碼提供給安裝的用戶。他們所需要做的就是檢查應用程序的流量,並且您的SendGrid API密鑰或帳戶已被泄露。

您需要向某個安全的後端服務器(或提供者,例如Parse或Azure)發出請求,然後從該服務器而不是客戶端應用發送電子郵件。

如果您想要調試代碼,請查看Github上的自述文件和示例。微軟的文檔很快就過時了。 https://github.com/sendgrid/sendgrid-csharp

+0

謝謝你的指導答案。其實我試圖通過Azure發送電子郵件,但它只在我更改了數據(插入,更新...)上的數據時才起作用。但我會搜索後端服務器謝謝。然後我有另一個問題:用戶可以從App.xaml.cs中的此代碼獲取我的Azure帳戶: public static MobileServiceClient MobileService = new MobileServiceClient( 「」,「」); 將應用程序中的重要數據存儲在應用程序中是否安全,而無需使用憑據和Web類? – Pumpkin