Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello fellow Monks.

I need to write a script which checks maintenance for a program running on a distant machine. I have limited rights on this machine, so no installing various CPAN modules.

The mail needs to be sent with data in the mail body, and the same data in a CSV file that will be sent as an attachment.
I thought I had it down pat, but the mail sends, and their is an attachment, but it is almost empty, unreadable file.

Could someone please tell me where I'm going wrong ? Any help is much appreciated.

Here's the code refering to the CSV file :

#!/usr/bin/perl use strict; use DBI; use Net::SMTP; use utf8; my @addr_to_send = qw/anton.harris@beirtelecom.com/; my $from_addr = 'systemplus@joursheureux.be'; my $smtp_addr = 'smtp.skynet.be'; 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("--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-Disposition: attachment; filename=\"$csvfile\ +"\n"); $smtp->datasend("Content-Type: application/text; name= $csvfile "); $smtp->datasend("\n"); open CSVFH, "< $csvfile"; while (<CSVFH>) { chomp; $smtp->datasend("$_\n"); } close CSVFH; } $smtp->datasend("--frontier--\n"); $smtp->dataend(); $smtp->quit; }

NB : the $_ that appear as links to other nodes should really just be '$_' but in between brackets.


In reply to Send mail with attachment using only SMTP by Mad Ant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-25 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found