in reply to Problems sending an email attachment using Net::SMTP

I wonder what the value of $subj is and whether that is causing problems. You could check the return values of your calls to datasend to ensure they are succeeding.

I tried on a default compile of perl 5.10.0 on CentOS 5, with $subj set to a simple string (as I didn't have your get_datetime()) and both the empty line after the Subject: header and the Content-type records were delivered.

  • Comment on Re: Problems sending an email attachment using Net::SMTP

Replies are listed 'Best First'.
Re^2: Problems sending an email attachment using Net::SMTP
by Argel (Prior) on Jun 27, 2009 at 06:24 UTC
    Did it come through with the CSV file as an attachment? The output I pasted in is from the email my hotmail account received (from the view message source option) so all of the text is making it through but the whole multipart aspect is broken.

    get_datetime() produces output like: 2009_06_26_21-35-37 so I don't think it would be causing a problem.

    Elda Taluta; Sarks Sark; Ark Arks

      With a little change, the CSV came through as an attachment.

      use strict; use warnings; use Net::SMTP; my $msg = "foo"; my $subj = "my test subject"; my $csvfile = "opnet_ace_cap_agent_audit_$subj.csv"; my $boundary = 'frontier'; my $hostname = "myhost"; my @to = ( "user\@localhost" ); my @csv = ( "one line of csv", "another line of csv", ); my $smtp = Net::SMTP->new('smtp.somecorp.com', Timeout => 60); $smtp->mail( "root\@$hostname.somecorp.com" ); $smtp->to( @to); $smtp->data(); foreach my $dst ( @to ) { $smtp->datasend( "To: $dst\n" ) } # @to is a global (ducks for cover) $smtp->datasend("Subject: Opnet: Ace Capture Agent Audit: $subj\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed; \n\tboundary=\"$bounda +ry\"\n"); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-type: text/plain\n"); $smtp->datasend("Content-Disposition: quoted-printable\n"); $smtp->datasend("\n$msg\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-Type: application/text; name=\"$csvfile\"\n") +; $smtp->datasend("Content-Disposition: attachment; filename=\"$csvfile\ +"\n"); $smtp->datasend("\n"); $smtp->datasend(\@csv); # Global array (ducks for cover again). $smtp->datasend("--$boundary--\n"); $smtp->dataend(); $smtp->quit;

      update: it's not very good CSV content, but it did come through as an attachment.

        Thanks ig!! As I indicated in my OP, your changes did the trick. I really appreciate the help!!

        Elda Taluta; Sarks Sark; Ark Arks