2015-07-21 152 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