2016-07-25 36 views
0

我們有一個iphone應用程序的cPanel,我們發送電子郵件給註冊用戶。爲了更早地發送電子郵件,我們有自己的服務器,但是從Gmail購買了電子郵件,以便他可以使用[email protected]登錄到Gmail。發送電子郵件使用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) 
+1

沒有任何代碼?真的很難... – 2016-07-25 11:26:10

+0

調試它,並在這裏發佈異常....「不工作」太寬.... – 2016-07-25 11:58:29

+0

@x ...:添加異常..其他任何你需要? –

回答

0

我想我也有這個問題,前一陣子。它與gmail的隱私設置有關。

您需要允許客戶端使用Gmail帳戶發送電子郵件。這個答案在計算器上可以幫助你: How to send an e-mail with C# through Gmail

+0

我已添加例外... –

+0

電子郵件正在運行,但只用於Gmail ... –

0

我不知道我的建議是否會對你有幫助,但是當我在android上發送gmail消息時,問題是一個錯誤的用戶名或密碼。 您第一次嘗試登錄gmail並且您的密碼或用戶名稱不正確,那麼在重新啓動您的應用程序之前您不能再嘗試,否則您將會登錄失敗,如果您重新啓動應用程序,則可以嘗試登錄。我認爲有一個在應用程序中使用Gmail的條件,包括一次嘗試登錄。好運

相關問題