简体   繁体   English

出现错误:-System.net.mail.SmtpException

[英]Getting error:-System.net.mail.SmtpException

When running the below code, I get 运行以下代码时,我得到

Unhandled Exception: System.Net.Mail.SmtpException 未处理的异常:System.Net.Mail.SmtpException

This code is for sending mail. 此代码用于发送邮件。 It works fine with Windows application, but I'm getting a runtime error on Mono for Android. 它可以在Windows应用程序上正常运行,但是在Android版Mono上出现运行时错误。 Smeone told me that System.net.mail is part of the System.dll assembly, but I don't know how to use it in my MonoDroid application. Smeone告诉我System.net.mail是System.dll程序集的一部分,但我不知道如何在我的MonoDroid应用程序中使用它。

Additional namespace is: "using System.Net.Mail;" 其他名称空间是:“使用System.Net.Mail;”

 string username = "abc@xyz.com";
 string password = "1234567890";
 System.Net.NetworkCredential nc = new
 System.Net.NetworkCredential(username, password);
 MailMessage MailMessage = new MailMessage();
 MailMessage.To.Add("pqr@xyz.com");
 MailMessage.Subject = "here is the subject";
 MailMessage.From = new System.Net.Mail.MailAddress("abc@xyz.com");
 MailMessage.Body = "Application run time was ";
 System.Net.Mail.SmtpClient SmtpClient = new System.Net.Mail.SmtpClient("
 smtp.gmail.com");
 SmtpClient.UseDefaultCredentials = false;

 SmtpClient.EnableSsl = true;
 SmtpClient.Credentials = nc;
 SmtpClient.Port = 587;
 SmtpClient.Send(MailMessage);

This runs fine on Windows. 在Windows上运行良好。 I'm running Mono for Android 4.2.7, Visual Studio 2010. 我正在为Android 4.2.7,Visual Studio 2010运行Mono。

Try below one as Test and then change it to your situation If it's working .Good Luck. 尝试以下一项作为测试,然后将其更改为您的情况。如果它起作用,好运。

using System;
using System.Net.Mail;
using System.Collections.Generic;
using System.Text;
using Gtk;
using GtkSharp;
using GLib;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

namespace KentSoft
    {
    class  printTest : Window
    {
    public  printTest() : base("Kent_Calisma")
    {
    try{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("yourmailadress@gmail.com");
    mail.To.Add("destinationmailadress@gmail.com");
    mail.Subject = "TEST";
    mail.Body = "This is for testing SMTP mail from GMAIL";
    SmtpServer.Port = 587;

    SmtpServer.Credentials = new System.Net.NetworkCredential("gmailusername without @gmail.com", "gmailpassword");

    SmtpServer.EnableSsl = true;
    ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

    SmtpServer.Send(mail);

}

catch(Exception e){
    Console.WriteLine("Ouch!"+e.ToString());
  }
}

public static void Main()
    {
   Application.Init();
   new printTest();
   Application.Run();
          }
        }
      }

You can get more details from Original Post 您可以从原始帖子中获取更多详细信息

暂无
暂无

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

相关问题 System.Net.Mail.SmtpException:邮箱不可用 - System.Net.Mail.SmtpException: Mailbox unavailable 尝试在System.dll中使用smtp'System.Net.Mail.SmtpException'发送电子邮件时出错 - error when trying to send email using smtp 'System.Net.Mail.SmtpException' in System.dll 如何修复 System.Net.Mail.SmtpException - How Can I Fix System.Net.Mail.SmtpException system.net.mail.smtpException:无法连接到远程服务器? - system.net.mail.smtpException :Unable to connect to the remote server? System.Net.Mail.SmtpException:该地址具有无效的主机名 - System.Net.Mail.SmtpException: The address has an invalid host name 如何正确处理System.Net.Mail.SmtpException? - How to correctly handle System.Net.Mail.SmtpException? System.Net.Mail.SmtpException {“发送电子邮件失败。”} - System.Net.Mail.SmtpException {“Failure Sending Email.”} MailMessage System.Net.Mail.SmtpException,尝试通过 C# 表单发送 email 时出错 - MailMessage System.Net.Mail.SmtpException, Error when trying to send email via C# form System.Net.Mail.SmtpException: 操作已超时。 asp.net 中的错误使用godaddy 托管发送邮件代码 - System.Net.Mail.SmtpException: The operation has timed out. error in asp.net send mail code using godaddy hosting System.Net.Mail.SmtpException:系统存储不足。 服务器响应如下:4.3.1系统资源不足 - System.Net.Mail.SmtpException: Insufficient system storage. The server response was: 4.3.1 Insufficient system resources
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM