0

I am trying to get Swiftmailer to work but keep getting "recipient rejected" messages.

What causes the "recipient rejected" response? Is this a response from the gmail server (gmail sensing this is SPAM)? Is there a way to overcome this? Otherwise, I will abandon Swiftmailer and try PHPMailer. I've had success with PEAR packages in the past but got tired of the configuration and was going to try Swiftmailer first...it shouldn't be this difficult right?

My Configuration:
- PHP 5.5.6
- Swiftmailer 5.0.3 (with Logger Plugin)
- Hosting by GoDaddy (yeah...I know)

Goal: Use Swiftmailer to send SMTP message from admin@mydomain.org to legit@gmail.com
(obviously the email addresses are placeholders for actual addresses)


Here is the PHP code: (same as example in Swiftmailer documentation)

<?php 
    require_once 'lib/swift_required.php';

    $transport = Swift_SmtpTransport::newInstance('smtp.mydomain.org', 25)
      ->setUsername('admin@mydomain.org')
      ->setPassword('mypassword')
      ;

    $mailer = Swift_Mailer::newInstance($transport);


    $logger = new Swift_Plugins_Loggers_EchoLogger();
    $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));

    $message = Swift_Message::newInstance('Wonderful Subject')
      ->setFrom(array('admin@mydomain.org' => 'admin'))
      ->setTo(array('legit@gmail.com' => 'recipient'))
      ->setBody('Here is the message itself')
      ;

    $result = $mailer->send($message);
    echo $logger->dump();
?>

Here is the relevant logger info:

    ...
    ++ Swift_SmtpTransport started
    ...
    >> RCPT TO: <legit@gmail.com>
    << 550 5.1.1 <legit@gmail.com> recipient rejected
    !! Expected response code 250/251/252 but got code "550", with message "550 5.1.1 <legit@gmail.com> recipient rejected "
    >> RSET
    << 250 2.0.0 OK
    ++ Stopping Swift_SmtpTransport
    >> QUIT
Community
  • 1
  • 1
Sparebrain
  • 111
  • 1
  • 11

1 Answers1

3

Not a "real" answer, but too long for the comment box:

Is this a response from the gmail server

Yes.

recipient rejected means that, somehow, the recipient (that is, the address you're sending mail to, legit@gmail.com`) is "rejected".

This can have a number of causes

  • Email address doesn't exist (anymore) (quite probable)
  • User mailbox is full (quite probable)
  • The account is blocked by gmail (quite probable)
  • the user set a filter to explicitly reject emails from you (not sure if this can be done using gmail, but it's technical possible).
  • Your message is considered spam (unlikely, you would probably get a different message)
  • ... many others...

It's somewhat unfortunate that gmail doesn't provide more info as to the cause. I can't find any documentation on gmail's error codes (550 is a generic "it failed" code), and usually these sort of messages are more verbose ...

What you could try:

  • Make very sure the email exists and is valid. Use a different gmail address (ie. one accessible by you) to be sure.
  • Check if you're blacklisted, for example using: http://mxtoolbox.com/blacklists.aspx
  • Try sending mail from smtp.mydomain.org, for example with the commandline mail utility (if it's a UNIX box), if this doesn't work, you know the problem is at the mail server, if it does work, you know the problem is at Swift mailer.
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
  • just to add to the blacklist possibility: gmail only uses the spamhaus blacklist, unless that has changed recently. any other listings should not impact your ability to deliver. but yeah, speaking from first hand this is not a blacklisting issue - they issue a code specific for that event (5.7.1). i upvoted your answer though, everything said here is spot on. – skrilled Feb 19 '14 at 00:39
  • The gmail account I'm sending to is my own gmail account so I know that it exists, is not full, is not blocked, and has no filter. This leads me to think gmail considers the email spam. This seems odd though because I used the most basic Swiftmailer example and it was blocked by one of the most popular email services? This doesn't bode well for Swiftmailer if this is the case. – Sparebrain Feb 19 '14 at 01:03
  • Follow-up: I can send mail using the mail utility. I suspect the problem is with Swiftmailer. This seems easy for others to duplicate/validate with their own gmail addresses. If gmail is blocking, this should be a more commonly reported problem. I suspect it is something else with my Swiftmailer settings? – Sparebrain Feb 19 '14 at 01:07
  • Checked the domain against the blacklist website noted by @Carpetsmoker: Listed 0 times – Sparebrain Feb 19 '14 at 01:11
  • @Sparebrain I'm not so certain it's Swift mailer's fault, but trying PHPMailer couldn't hurt & shouldn't be too much effort... It also appears you snipped some output from the log? It might be helpful if you could post the full log. – Martin Tournoij Feb 19 '14 at 01:25