in reply to Re^5: Using Net::SMTP to send pdf attachment
in thread Using Net::SMTP to send pdf attachment
Hi poj thanks. Here's the complete code:
use strict; use Net::SMTP; use MIME::Base64; my $smtphost = 'some_smtp_host'; my $username = 'username'; my $password = 'password'; my $emailto = 'to@hello.com'; my $emailfrom = 'from@hello.com'; my $subject = 'Hello world'; my $message = 'Test message'; my $smtp = Net::SMTP->new($smtphost, Debug => 1, Timeout => 5); $smtp->datasend("AUTH LOGIN\n"); $smtp->datasend(encode_base64($username)); $smtp->datasend(encode_base64($password)); $smtp->mail($emailfrom); $smtp->to($emailto); $smtp->data(); my $boundary = 'frontier'; my $attachBinaryFile = '18560243.pdf'; $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundar +y\"\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-type: text/plain;\n"); $smtp->datasend("\nSome plain text here in the body of the email\n"); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-Type: appliaction/pdf; name=\"$attachBinaryFi +le\"\n"); $smtp->datasend("Content-Transfer-Encoding: base64\n"); $smtp->datasend("Content-Disposition: attachment; filename=\"$attachBi +naryFile\"\n"); $smtp->datasend("\n"); my $buf; open(DAT, "/path/18560243.pdf") || die("Could not open binary file!"); binmode(DAT); local $/=undef; while (read(DAT, my $picture, 4096)) { $buf = &encode_base64( $picture ); $smtp->datasend($buf); } close(DAT); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->dataend(); $smtp->quit; sub date_r { my ($monthday, $mon, $yr, $ time, $hour, $str); my (@lt) = (); @lt = localtime(); $monthday = $lt[3]; $mon = $lt[4]+1; $yr = $lt[5] + 1900; $hour = $lt[2]; $time = sprintf("%02d:%02d:%02d", $hour, $lt[1], $lt[0]); $str = $mon . '/' .$monthday . '/' . $yr . ' ' . $time; return $str; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Using Net::SMTP to send pdf attachment
by poj (Abbot) on Mar 16, 2018 at 17:43 UTC | |
by Anonymous Monk on Mar 17, 2018 at 00:23 UTC | |
by poj (Abbot) on Mar 17, 2018 at 15:55 UTC | |
by Anonymous Monk on Mar 18, 2018 at 05:49 UTC |