Web Hosting Talk







View Full Version : Net::SMTP question


kapot
07-15-2004, 03:19 PM
I tried to send email using perl, but it always sent without subject.
Anyone know how to fix this ?

#!/usr/bin/perl

use Net::SMTP;

$from = "support\@mycompany.com";
$subject = "A subject";

open(TXT, "address.txt") || die "Cant open address.txt $!\n";
@Email = <TXT>;
close(TXT);

open F, "email.txt" or die "Error reading email.txt: $!";
{local $/; $body = <F>;}
close F;

foreach $email (@Email)
{
$smtp = Net::SMTP->new('localhost');
$smtp->mail("$from");
$smtp->to("$email");

$smtp->data();
$smtp->datasend('To: '.$email."\n");
$smtp->datasend('From: '.$from."\n");
$smtp->datasend('Subject: '.$subject."\n");
$smtp->datasend($body."\n");
$smtp->dataend();
$smtp->quit;
}

boonchuan
07-15-2004, 11:32 PM
No u need to be at the command prompt
type ppm
ppm > search net::smtp
U will get a list
Install them and that's it

SimplyDiff
07-16-2004, 08:14 AM
The headers of an e-mail need to be seperated from the body by two \ns, actually should be CRLFs, but \n usually works too. So, in your format you would want the subject to end with two \n. That's why in the documentation for Net::SMTP, in the example, after the subject is sent, a blank line is sent.

$smtp->datasend('Subject: '.$subject."\n\n");