简体   繁体   中英

Getting Exception Sending Email through Smtp Client in Xamarin

I am getting an error when sending Email through c# code in my Android App

534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 n10sm18967460pap.16 - gsmtp

MailMessage message = new MailMessage();
            message.From = new MailAddress("xxx@gmail.com");
            message.To.Add(new MailAddress("xxx@gmail.com"));
            message.Subject = "Hai";
            message.Body = "test mail";

            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.EnableSsl = true;

            client.Credentials = new System.Net.NetworkCredential("xx@gmail.com", "password");
            ServicePointManager.ServerCertificateValidationCallback = delegate(object sende,X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslpolocy) {
                return true;
            };

            //client.DeliveryMethod = SmtpDeliveryMethod.Network;

            client.Send(message);
            Toast.MakeText(this, "Sending mail...", ToastLength.Long).Show();

I am sending email in Xamarin But i am getting above exception . Canyou please help me how can i resolve.

Here is a solution which I found online and it did work for me :

  1. Open standard non-incognito Google window (I will reference it as window 1) and logout from Google account.
  2. Open incognito Google window (I will reference it as [2]) and logout from Google account.
  3. In window 1, login to your personal email xx@gmail.com
  4. In window 1, open account security settings by navigating to My Account -> Sign-in & Security and scroll down to "Allow less secure apps" setting. If this setting is Turned to ON, Turn it to OFF, wait 5 seconds, and Turn it to ON again (this was quite crucial as far as I understand). If this setting is turned to OFF, turn it to ON.
  5. In window 1, open https://accounts.google.com/DisplayUnlockCaptcha link and click button to unlock CAPTCHA. 5.1. Do not do anything in 1
  6. In window 2, login to your company email or some other email
  7. In window 2, open https://accounts.google.com/DisplayUnlockCaptcha link and click button to unlock CAPTCHA
  8. In window 2, in mail.google.com tab, open Settings -> Accounts, click Add another email address you own
  9. In opened modal window, enter whatever name and personal email address - xx@gmail.com and click Next Step
  10. SMTP Server should be set to smtp.gmail.com, port to 587, username to xx@gmail.com (NOT just john.doe), type in password from your personal xx@gmail.com address (please note that I don't have 2 Step Verification enabled, if you have - please note that you may need to enter different password)
  11. Click Connect and hopefully you won't receive noisy "Server response: 534-5.7.14" error

This approach was encountered quite accidentally, so Google Help authors should write more specific about this OR Google developers should try to reproduce and fix this issue.

Link to this original article is here

在我的gmail设置中启用“允许安全性较低的应用程序”后,其工作正常。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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