0

We have an cpanel for an iphone app where we send email to registered users. For sending email earlier we had our own server, however purchased email from gmail so that he can login to gmail using app@mywebsite.com.

To make working we changed the code to gmail setting and all was working fine. Suddenly today client called us saying email is not working.

Any idea all of sudden why gmail stop sending emails? I see that at start it works but after sometime google stops sending emails.

Below is the code used.

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;
}

Below is the exception I have

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)
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

2 Answers2

0

I think I also had this problem a while ago. It had something to do with the privacy settings of gmail.

You need to allow clients to send email with the gmail account. This answer on stackoverflow can help you: How to send an e-mail with C# through Gmail

Community
  • 1
  • 1
Jurgen Vandw
  • 631
  • 8
  • 27
0

I do not know if my suggestion will help you,but when i was working at sending gmail messages on android,the problem was a wrong user name or password. first time you try to sign in to gmail and you have a wrong password or user name then you cannot try again until you restart your app or you will have a failed sign in,if you restart your app then you can try sign in.I think there are a conditions for using gmail in apps including one try for sign in.good luck

phoenix
  • 351
  • 4
  • 11