Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Send mail with attachment using only SMTP

by tachyon-II (Chaplain)
on May 29, 2008 at 18:43 UTC ( #689064=note: print w/ replies, xml ) Need Help??


in reply to Send mail with attachment using only SMTP

Email really only deals with the ASCII charset. As a result anything outside of this charset really needs to be base 64 encoded. You are already torturing the mailserver by sending non ascii chars in the body (ie e acute). It may be your CSV contains non ASCII chars and this is causing the mail server to barf.

However, the problem is probably this:

$smtp->datasend("Content-type: multipart/mixed; boundary=\"frontier\"\n"); # needs to be all on one line or like this: $smtp->datasend("Content-type: multipart/mixed; boundary=\"frontier\"\n");

The whitespace before boundary indicates that is the line continuation (it is), but in your code you send it as a header line (it isn't). It does not really explain your symptoms as described, but is wrong and should fail.

As you seem hell bent on rolling your own solution I suggest you base64 encode your CSV and send it as binary. You can just cut and paste the < 30 lines of code from MIME::Base64 encode routine to do this. BTW I would not use just "frontier" as your multipart boundary. "==frontier==", which will become "--==frontier==" would seem a far more improbable boundary.

You can make your code a lot more readable if you use a HEREDOC.

my $body = .... my $attach = .... # base 64 encoded data my $a_name = ..... my $email =<<EMAIL; MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==frontier==" This is a multi-part message in MIME format. --==frontier== Content-Transfer-Encoding: binary Content-Type: text/plain $body --==frontier== Content-Transfer-Encoding: base64 Content-Type: application/octet-stream; name="$a_name" $attach --==frontier==-- EMAIL $smtp->datasend($email) $smtp->dataend() $smtp->quit;


Comment on Re: Send mail with attachment using only SMTP
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2015-07-30 02:18 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 (269 votes), past polls