Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Gmail Send problem

by IvanH (Acolyte)
on Sep 17, 2014 at 16:24 UTC ( [id://1100943]=perlquestion: print w/replies, xml ) Need Help??

IvanH has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am using Email::Send::SMTP::Gmail to send a newsletter. I set up a loop to send it to about 150 addresses. I know that the first few went successfully and the last few did not, so I suspect my coding to detect an error in the send is incorrect. I have been told that $mail will return -1 if it fails and therefore used the following code: Have I set this up correctly?

$mail->send(-to=>"$email", -subject=>"$subject", -body=>"$emailtext",-contenttype=>'text/html'); if ($mail == -1) { die "Mail send error: $!\n"; } else { print "Success!\n\n"; print OUTFILE "Success!\n\n"; }

Thanks for any help,

Ivan

Replies are listed 'Best First'.
Re: Gmail Send problem
by Corion (Patriarch) on Sep 17, 2014 at 16:53 UTC

    $mail will never return anything.

    Maybe $mail->send returns something, but you never store the result of that function call.

    Also note that more likely, Google blocks your mails after the first 10 or so, as you might be a spammer.

      As far as I can tell from Google's documentation they block after 500, and disable the email account for a day. I sent much less than that and the account wasn't blocked so I don't think that's the problem. How would I know if $mail->send failed for some reason.

      Thanks

        The Email::Send::SMTP::Gmail POD says you can use -verbose. When the documentation is inadequate, you should look at the source code, which shows that "send" can return a list. Try:
        my @returns = $mail->send(-to=>"$email", -subject=>"$subject", -body=>"$emailtext",-contenttype=>'text/html' -verbose=>1); print "@returns\n";
Re: Gmail Send problem
by blue_cowdawg (Monsignor) on Sep 17, 2014 at 16:58 UTC
        I set up a loop to send it to about 150 addresses. I know that the first few went successfully and the last few did not

    You might want to look at the documentation for the module as you've made a couple of bad assumptions. $mail is never going to equal -1.

    The symptoms you are describing sound more like throttling on the GMail side. I know Yahoo throttles and I'd not be surprised if Google did as well.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; Blog: http://blog.berghold.net Warning: No political correctness allowed.

      I don't think it's Gmail blocking as their documentation says they limit at 500/day, which is much more than I sent. Is there a way to know if $mail->send failed for some reason?

      Thanks

        By "throttling", blue_cowdawg did not mean blocking, but rather limiting the rate at which new messages can be sent

        You might consider adding a sleep(1) in your loop.

        Also, maybe you should consider using a list service. You send your message to the service, then it forwards it to the list subscribers.

        Since you are already using Google, Google Groups is one list service to consider. In my (limited) experience of subscribing to Google Groups, subscribers don't have to have a Google account to do so (assuming it hasn't changed since the last time I used a non-Google account with a Google Group).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1100943]
Approved by toolic
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-18 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found