【问题标题】:sending emails using gmail account stopped working after some time使用 gmail 帐户发送电子邮件在一段时间后停止工作
【发布时间】:2016-11-28 17:14:17
【问题描述】:

我们有一个用于 iphone 应用程序的 cpanel,我们可以在其中向注册用户发送电子邮件。为了更早发送电子邮件,我们有自己的服务器,但是从 gmail 购买了电子邮件,以便他可以使用 app@mywebsite.com 登录到 gmail。

为了正常工作,我们将代码更改为 gmail 设置,一切正常。今天突然客户打电话给我们说电子邮件不起作用。

突然间知道为什么 gmail 停止发送电子邮件了吗?我看到它在开始时有效,但一段时间后谷歌停止发送电子邮件。

下面是使用的代码。

public static bool SendMail(string From, string To, string SMTPServer, string UserName, string Password, string Subject, string Body, string AttachmentFilePath = null)
{
    if (!string.IsNullOrEmpty(From) && !string.IsNullOrEmpty(To) && !string.IsNullOrEmpty(SMTPServer) && !string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
    {
        try
        {
            MailMessage MailMessageObj = new MailMessage();
            MailMessageObj.From = From;
            MailMessageObj.To = To;
            MailMessageObj.Subject = Subject;
            MailMessageObj.Body = Body;
            MailMessageObj.BodyFormat = MailFormat.Html;
            MailMessageObj.Priority = MailPriority.High;
            MailMessageObj.BodyEncoding = System.Text.Encoding.UTF8;
            if (!string.IsNullOrEmpty(AttachmentFilePath))
                MailMessageObj.Attachments.Add(new System.Web.Mail.MailAttachment(HttpContext.Current.Server.MapPath(AttachmentFilePath)));
            MailMessageObj.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
            MailMessageObj.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = UserName;
            MailMessageObj.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = Password;

            System.Web.Mail.SmtpMail.SmtpServer = SMTPServer;
            System.Web.Mail.SmtpMail.Send(MailMessageObj);
            return true;
        }
        catch (Exception ex)
        {
            LogException(ex);
            return false;
        }
    }
    return false;
}

下面是我的例外

Exception Message :   
The server rejected one or more recipient addresses. The server response was: 550 5.1.1  https://support.google.com/mail/answer/6596 c202si11359510oib.218 - gsmtp


Exception InnerException :   
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: The server rejected one or more recipient addresses. The server response was: 550 5.1.1  https://support.google.com/mail/answer/6596 c202si11359510oib.218 - gsmtp

   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)

Exception StackTrace :   
   at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
   at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message)
   at System.Web.Mail.SmtpMail.Send(MailMessage message)
   at Utilities.SendMail(String From, String To, String SMTPServer, String UserName, String Password, String Subject, String Body, String AttachmentFilePath)

【问题讨论】:

  • 没有任何代码?真的很难……
  • 调试它并在这里发布异常......“不工作”太宽泛了......
  • @x... :添加了异常......你还需要什么?
  • 您可以在“support.google.com/mail/answer/6596”中看到来自google的错误消息,收件人地址不存在。
  • @x...:我使用的地址是有效的电子邮件...我使用了我的个人...即使我也尝试使用我的 hotmail...除了 gmail 没有任何效果...]

标签: c# asp.net email gmail


【解决方案1】:

我想我前段时间也遇到过这个问题。这和gmail的隐私设置有关。

您需要允许客户使用 gmail 帐户发送电子邮件。这个关于stackoverflow的答案可以帮助你: How to send an e-mail with C# through Gmail

【讨论】:

    【解决方案2】:

    我不知道我的建议是否会对你有所帮助,但是当我在 Android 上发送 gmail 消息时,问题是用户名或密码错误。 当您第一次尝试登录 gmail 并且您的密码或用户名错误时,您必须重新启动应用程序才能重试,否则您将无法登录,如果您重新启动应用程序,那么您可以尝试登录。我认为在应用程序中使用 gmail 有一个条件,包括一次尝试登录。祝你好运

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-19
      • 2012-03-30
      • 1970-01-01
      • 2011-04-06
      • 2015-12-29
      • 2017-12-21
      • 2011-12-15
      • 2013-03-24
      相关资源
      最近更新 更多