我們有一個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)
沒有任何代碼?真的很難... – 2016-07-25 11:26:10
調試它,並在這裏發佈異常....「不工作」太寬.... – 2016-07-25 11:58:29
@x ...:添加異常..其他任何你需要? –