Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: sending e-mail using perl script

by roho (Abbot)
on Aug 12, 2012 at 15:49 UTC ( #986964=note: print w/ replies, xml ) Need Help??


in reply to sending e-mail using perl script

Mime::Lite is a good choice. The following program uses it to send both text and attachments.

#!/usr/bin/perl use MIME::Lite; # Set this variable to your smtp server name my $ServerName = "smtp.comcast.net"; my $from_address = 'me@comcast.net'; my $to_address = 'me@hotmail.com'; my $subject = 'MIME Test: Text'; my $mime_type = 'text'; my $message_body = "Testing text in email.\n"; # Create the initial text of the message my $mime_msg = MIME::Lite->new( From => $from_address, To => $to_address, Subject => $subject, Type => $mime_type, Data => $message_body ) or die "Error creating MIME body: $!\n"; # Attach the text file my $filename = 'C:\tmp\test.txt'; my $recommended_filename = 'test.txt'; $mime_msg->attach( Type => 'application/text', Path => $filename, Filename => $recommended_filename ) or die "Error attaching text file: $!\n"; # encode body of message as a string so that we can pass it to Net::SM +TP. my $message_body = $mime_msg->body_as_string(); # Let MIME::Lite handle the Net::SMTP details MIME::Lite->send('smtp', $ServerName); $mime_msg->send() or die "Error sending message: $!\n";

"Its not how hard you work, its how much you get done."


Comment on Re: sending e-mail using perl script
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986964]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2015-07-08 04:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls