Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

For my use-case, I’ve never had easy access to a private/internal mail server. I’ve always used SMTP methods to connect to gmail or yahoo. I haven’t ever tried any of the other solutions (MailTools, Mail::Sendmail), so I don’t know if they work for my scenario. It does look like as of now (Feb 2019), MIME::Lite and Mail::Sender are not recommended by their respective maintainers.

My solution involves 3 modules:

I’ve tested this on gmail and yahoo. For gmail, I had to go into my account settings and allow less secure apps to access my account. I think this just refers OAuth. You will still use TLS/SSL to talk to Gmail, so you won't be sending your plaintext password over the Internet.

use MIME::Entity; use Email::Sender::Simple qw( sendmail ); use Email::Sender::Transport::SMTP; $user = "myself\@gmail.com"; #must be a legitimate email account $pass = "mypassword"; $mailhost = "smtp.gmail.com"; #for yahoo, use smtp.mail.yahoo.com $rcpt = other.user@other.com; #could also send it back to myself; $file = "my_picture.jpg"; $debug = 0; #enable by setting to 1 my $transport = Email::Sender::Transport::SMTP->new( host => $mailhost, port => 465, ssl => "ssl", sasl_username => $user, sasl_password => $pass, debug => $debug ); my $mime = MIME::Entity->build( To => $rcpt, From => $user, Subject => "Simple MIME from Perl", Type => "multipart/mixed"); $mime->attach(Data => "Hungry? Eat a Milky Way", Type => "text/plain"); if(defined $file and -e $file) { $mime->attach(Path => $file, Encoding => "base64", Disposition => "attachment"); } sendmail($mime, { transport => $transport });

In reply to Re: How do I send an email with Perl (including an attachment)? by skleblan
in thread How do I send an email with Perl (including an attachment)? by Paav

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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others sharing their wisdom with the Monastery: (2)
    As of 2025-06-15 17:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.