【发布时间】: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 没有任何效果...]