Hi all,

I'm a new perl user. I'm trying to send a text file as an attachment through gmail. I tried MIME::Lite, Mail::Sender, Mail::Webmail::Gmail, and Net::SMTP::Server.

I can't connect to gmail at all using any of those, so I was wondering which one of those or which other packages I should use instead that would allow me to send a 100kb text file as an attachment?

I am not married to sending the email+attachment through gmail (although I prefer gmail), I just need an efficient/effective way to send an email w/ attachment, and I am overwhelmed by the millions of way it can be done in Perl. Any suggestions would be much appreciated.

I added the code from my various attempts below:
my $from = 'email@gmail.com'; my $to = 'email@email.com'; my $Subject = 'subj'; my $filepath = 'c:\programming'; my $txttype = 'text/plain'; my $filenm = 'txt.txt'; my $user = 'username'; #confused if I need to use my email address as +username or just username my $passwd = 'pass'; #--------- NET::SMTP::SERVER ---------- my $smtp = Net::SMTP::Server->new( Host => 'smtp.gmail.com', Hello => 'smtp.gmail.com', Timeout => 30, Debug => 1, Auth => ($user, $passwd), ); $smtp->mail("email\@gmail.com"); $smtp->recipient("email\@gmail.com", \ "email\@email.com"); $smtp->datasend("From: email\@gmail.com"); $smtp->datasend("To: email\@email.com"); $smtp->datasend("Subject: This is a test"); $smtp->datasend("\n"); $smtp->datasend("blahblah"); $smtp->dataend; $smtp->quit; # This resulted in an error that the program wsa unable to connect to +gmail #------------ MAIL::WEBMAIL::GMAIL -------- my $gmail = Mail::Webmail::Gmail->new( username => $user, password => +$passwd ); $gmail->send_message( to => $to, subject => 'Test Message', msgbody => + 'This is a test.' ); # This completed without error, but I never recieved an email #------------ MAIL::SENDER ----------------- my $sender=Mail::Sender->new; if ($sender->MailMsg({ smtp => 'smtp.gmail.com', from => 'email@gmail.com', to => 'email@email.com', subject => 'test email', msg => 'testing email', auth => 'LOGIN', authid => $user, authpwd => $passwd, }) < 0) { die "$Mail::Sender::Error\n"; } print "Mail sent OK."; # This was not able to connect either #------------ MIME::LITE -------------------- my $msg = MIME::Lite->new( From => $from, To => $to, Subject => $Subject, Data => "Blah blah" #smtp => 'smtp.gmail.com' ); $msg->attr("content-type" => "multipart/mixed"); #for each attachment: $msg->attach( Type => "text/plain", Path => $filepath, Filename => $filenm, Disposition => "attachment" ); MIME::Lite->send('smtp','smtp.gmail.com', Port => '465',Debug => '1', +Hello => 'gmail.com' , User=>$user, Password =>$passwd, Timeout => 60 +); $msg->send(); # This resulted in not being able to connect to gmail either


I tried to connect a few different ways and was unable to send the email. I am working on a Windows 7 PC, ActivePerl. I am just trying to send the email, not really vested in sending it through gmail. I tried variations on my username (email address, v username) and I changed the port to 587 and 25.

I am not confident in the quality of my code since I am new to this, so if anyone has a better way to send it that would be great.

As an aside, do I need to configure something on my machine for it to send emails? Is there some default email sending setting?

Thanks!

In reply to What is the easiest/most efficient way to send an email w/ attachment through gmail by nervousmark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.