Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Send mail with attachment using only SMTP

by Mad Ant (Novice)
on May 29, 2008 at 19:11 UTC ( #689069=note: print w/replies, xml ) Need Help??

in reply to Send mail with attachment using only SMTP

Found the problems.

Replace lines :

Swap the 2 following lines :
$smtp->datasend("Content-Disposition: attachment; filename=\"$csvfile\"\n");
$smtp->datasend("Content-Type: application/text; name= $csvfile ");

And finally, replace
$smtp->datasend("Content-Type: application/text; name= $csvfile ");
$smtp->datasend("Content-Type: application/text; name=\"$csvfile\"\n");

Hope this helps anyone elso who may encounter the problem.
  • Comment on Re: Send mail with attachment using only SMTP

Replies are listed 'Best First'.
Re^2: Send mail with attachment using only SMTP
by Mad Ant (Novice) on May 29, 2008 at 19:53 UTC

    @ almut : the line you mentionned appeared on 2 lines when copy/pasting, it normally appears on one line. And I formot to close the <code> tags at the end. I'll get them right next time :)

    @ tachyon-II : I'm still not 100% comfortable with all the ins and outs of Perl, coming from a ASM/C/C++/Java background. So I'll have to look into the HERECDOC stuff soon. thanks for the heads-up.

      You can edit your node and have it right this time. When you do you ought add: "Update: fixed code tags" to your node so later visitors are not confused by almut's reply.

      Perl is environmentally friendly - it saves trees
Re^2: Send mail with attachment using only SMTP
by Argel (Prior) on Jun 27, 2009 at 01:02 UTC
    I think I made the corrections correctly. Going to give this a try in one of my programs so I thoguht I would pass it along to anyone else who stumbles across it. Thanks for the update Mad Ant!
    #!/usr/bin/perl use strict; use DBI; use Net::SMTP; use utf8; my @addr_to_send = qw/; my $from_addr = ''; my $smtp_addr = ''; my $csvfile = "appelerr.csv"; ... # gets info from a database, creates a CSV file foreach my $to_send (@addr_to_send) { print "Sending mail to $to_send\n"; my $smtp = Net::SMTP->new($smtp_addr); $smtp->mail($from_addr); $smtp->to($to_send); $smtp->data(); $smtp->datasend("Subject: Appels S+ erronés"); $smtp->datasend("\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed; boundary=\"frontier\"\n"); $smtp->datasend("\n--frontier\n"); $smtp->datasend("Content-type: text/plain\n"); $smtp->datasend("Explication sur cet e-mail :\n"); $smtp->datasend("Cet e-mail contient la liste des appels effectués par + les pensionnaires et qui ne se sont pas terminés normalement.\n"); $smtp->datasend("Il peut s'agir d'un moment où l'infirmière a pu résou +dre les raisons de l'appel sans devoir appeler la chambre,\n"); $smtp->datasend("puis effectue un reset, ou que le pensionnaire, impat +ient, sonne de manière répétitive,\n"); $smtp->datasend("mais cela peut également etre un temps de réponse bea +ucoup trop long.\n\n"); if ($#badcalls < 0) { $smtp->datasend("Aucun appel erroné n'a été détecté.\n"); } else { for (sort @badcalls) { print "Bad call in line : $_ : $dbtime$_ - $dbroomid$_ - $dbevent$_\n" +; $smtp->datasend("$dbtime$_ - numèro de local : $rooms{$dbroomid$_}\n") +; } # THIS IS WHERE THE ATTACHMENT IS DONE $smtp->datasend("--frontier\n"); $smtp->datasend("Content-Type: application/text; name=\"$csvfile\"\n") +; $smtp->datasend("Content-Disposition: attachment; filename=\"$csvfile\ +"\n"); $smtp->datasend("\n"); open CSVFH, "< $csvfile"; while (<CSVFH>) { chomp; $smtp->datasend("$_\n"); } close CSVFH; } $smtp->datasend("--frontier--\n"); $smtp->dataend(); $smtp->quit; }

    Elda Taluta; Sarks Sark; Ark Arks

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-09-26 09:15 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (117 votes). Check out past polls.