简体   繁体   English

Windows Phone 8 sendGridMessage编译错误

[英]Windows Phone 8 sendGridMessage Compile error

   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);
   }

My application is Windows Phone 8.1, I try to send mail via sendGrid I created an account and include libraries to code but it gives 3 error: 我的应用程序是Windows Phone 8.1,我尝试通过sendGrid发送邮件,我创建了一个帐户,并包含要编写代码的库,但出现3个错误:

  1. error CS0570: 'SendGrid.SendGridMessage.From' is not supported by the language 错误CS0570:语言不支持“ SendGrid.SendGridMessage.From”
  2. error CS1502: The best overloaded method match for 'SendGrid.Web.Web(string)' has some invalid arguments 错误CS1502:“ SendGrid.Web.Web(string)”的最佳重载方法匹配具有一些无效的参数
  3. error CS1503: Argument 1: cannot convert from 'System.Net.NetworkCredential' to 'string' 错误CS1503:参数1:无法从'System.Net.NetworkCredential'转换为'string'

I have used this site" https://azure.microsoft.com/tr-tr/documentation/articles/sendgrid-dotnet-how-to-send-email/ " as reference. 我已使用此站点“ https://azure.microsoft.com/tr-tr/documentation/articles/sendgrid-dotnet-how-to-send-email/ ”作为参考。

Do errors stem from because app is a Windows Phone app or what? 是因为应用程序是Windows Phone应用程序还是其他原因导致错误?

And is there any other way to send an email by declaring "from" within code? 还有其他方法可以通过在代码内声明“发件人”来发送电子邮件吗?

This isn't really an answer to your question, but it's important enough I made it an answer and not a comment. 这实际上不是您所提问题的答案,但重要的是,我将其设为答案而不是评论。

This is not a secure way to send email from a mobile device, because you are giving the code that contains the credentials to users that install. 这不是从移动设备发送电子邮件的安全方法,因为您正在向安装用户提供包含凭据的代码。 All they need to do is inspect the traffic from your app and your SendGrid API key or account is compromised. 他们所需要做的只是检查来自您应用程序的流量,并且您的SendGrid API密钥或帐户已受到攻击。

You need to make a request to some secure backend server (or provider, eg Parse or Azure), and then send the email from that server rather than the client app. 您需要向某个安全的后端服务器(或提供程序,例如Parse或Azure)进行请求,然后从该服务器而不是客户端应用程序发送电子邮件。

If you want to debug the code though, check out the readme and example on Github. 如果您想调试代码,请查看Github上的自述文件和示例。 Microsoft's docs go out of date rather quickly. 微软的文档很快就过时了。 https://github.com/sendgrid/sendgrid-csharp https://github.com/sendgrid/sendgrid-csharp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM