Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Using Net::SMTP to send email attachments

by huck (Prior)
on Apr 30, 2017 at 19:18 UTC ( [id://1189217]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Using Net::SMTP to send email attachments
in thread Using Net::SMTP to send email attachments

It would be helpful to see what you did try

You may have one too many $smtp->datasend("--$boundary\n"); in there. you dont want a boundary before the main text. The example seems to have one.

Replies are listed 'Best First'.
Re^5: Using Net::SMTP to send email attachments
by astrobal (Acolyte) on May 01, 2017 at 06:00 UTC

    Here is the script I have been trying. I have tried commenting out various boundary lines, but without any improvement on the fact that the text part, "This is some text", is coming through as an attachment and the main body of the email is empty. The binary file attachment is coming through just fine though, so there is progress :-)</P

    Thanks again for looking

    #!/usr/bin/perl print "Content-type: text/html\n\n"; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use warnings; use Net::SMTP; use MIME::Base64; my ($buf, $picture); my $company = 'my_company.com'; my $path = "/home/sites/$company/public_html"; my $attachBinaryFile = "image.jpg"; my $boundary = 'frontier'; my $passwd = "password"; my $contact = "name"; my $email = "info\@$company"; $smtp = Net::SMTP->new("mail.$company", Timeout => 30,Debug => 0,); $smtp->datasend("AUTH LOGIN\n"); $smtp->response(); $smtp->datasend(encode_base64("$contact\@$company") ); $smtp->response(); $smtp->datasend(encode_base64("$passwd") ); $smtp->response(); $smtp->mail("$contact\@$company"); $smtp->to($email); $smtp->cc(); $smtp->data(); $smtp->datasend("To: $email\n"); $smtp->datasend("From: $contact\@$company\n"); $smtp->datasend("Cc: info\@$company\n"); $smtp->datasend("Subject: Trial to see if this will come through\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundar +y\"\n"); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-type: text/plain; charset=\"UTF-8\"\n"); $smtp->datasend("Content-Disposition: quoted-printable\n"); $smtp->datasend("\n"); $smtp->datasend("\nThis is some text.\n"); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-Type: image/jpeg; name=\"$attachBinaryFile\"\ +n"); $smtp->datasend("Content-Transfer-Encoding: base64\n"); $smtp->datasend("Content-Disposition: attachment; filename=\"$attachBi +naryFile\"\n"); $smtp->datasend("\n"); open(DAT, "$path/$attachBinaryFile") || die("Could not open binary fil +e!"); binmode(DAT); local $/=undef; while (read(DAT, $picture, 4096)) { $buf = &encode_base64( $picture ); $smtp->datasend($buf); } close(DAT); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->dataend(); $smtp->quit; print "Mail sent\n"; exit; print "</body></html>";

      Try changing this

      $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundar +y\"\n"); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-type: text/plain; charset=\"UTF-8\"\n"); $smtp->datasend("Content-Disposition: quoted-printable\n"); $smtp->datasend("\n");
      to this
      $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundar +y\"\n"); $smtp->datasend("Content-type: text/plain; charset=\"UTF-8\"\n"); $smtp->datasend("Content-Disposition: quoted-printable\n"); $smtp->datasend("\n");
      That matches what i see in my pop3 mailboxes better

        Sorry Huck, that did not do it. Still get two attachments.

        I really appreciate your help - if you have any other ideas, do holler!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found