[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] SMTP and setting mail subject



At 12:52 AM +0100 on 11/25/96, Ann Galea Baron wrote:


}Hi to all,
}
}I attach a script below for some comments from the more experienced. I
}intend it to take a hash %mail and use it to send an email via SMTP.pm, the
}connection being established within an eval statement to capture any
}failure in the connection -- passing control to a general error-reporting
}routine if anything goes wrong. It seems to work but I have two
}difficulties:
}
}(a) how can I use SMTP.pm to set the email header? All the text I pass
}    to SMTP.pm seems to be going into the body of the email;

You prepend it to the body of the email, separated by a single blank line.
For example,

$smtp->datasend("To: recipient\n");
$smtp->datasend("From: sender\n");
$smtp->datasend("Subject: something\n");
$smtp->datasend("X-header: whatever\n");
$smtp->datasend("\n");
$smtp->datasend("This is a body line\n");

->to and ->mail don't build any headers, but instead fill in the argument
of the SMTP commands MAIL FROM and RCPT TO.  For a slightly friendlier way
to build e-mail, which gives you control over headers, take a look at
Mail::Internet, in
the MailTools package.  The MacPerl version is at
<ftp://mors.gsfc.nasa.gov/pub/MacPerl/Scripts/>.  It eventually just uses
Net::SMTP to send the mail, but gives a little friendlier interface.

}(b) do more experienced eyes  detect any major bug in the way I use SMTP?
}    I have to admit that the script is blindly cribbed and put together
}    from fragments I have seen on this list and the archive (mostly Paul
}    Schinder's contributions). It works, but I don't know why :-)
}
}Thanks in advance,
}
}Gauden Galea
}http://www.synapse.net.mt
}
}
}##  ###################################################  #
}##  Connect to SMTP server and send mail                 #
}##  ###################################################  #
}
}sub sendMail {
}        use SMTP;
}
}        my ($err) = "Something went wrong with the mail server;
}                        it could be busy and not responding.
}                        Please try again at some other time.";
}
}        eval <<'TEST';
}        $smtp = Net::SMTP->new($mail{'mailhost'});
}        $smtp->mail($mail{'from'})                   ;
}        $smtp->to($mail{'to'})                       ;
}        $smtp->data()                                ;
}        $smtp->datasend("$mail{'subject'}\n")        ;
}        $smtp->datasend("\n")                        ;
}        $smtp->datasend("$mail{'text'}\n")           ;
}        $smtp->dataend()                             ;
}        $smtp->quit                                  ;
}TEST
}        if ($@) { &doError ($err) }
}
}}


--------
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693
Greenbelt, MD 20770
schinder@pjstoaster.pg.md.us