Hello,
I run xpanel on my server, and the program is sending emails to the users using sendmail. But the users on the server are also able to send email trough sendmail.
Now i'd like to stop sendmail completely and send the email trough an external smtp server.
To do this I have installed the folloing modules:
http:/search.cpan.org/~gbarr/libnet-1.19/Net/SMTP.pm
http:/search.cpan.org/~apleiner/Net-SMTP_auth-0.07/SMTP_auth.pm
With SMTP_auth comes a test program, and the program is telling me everything is ok, and it is able to successfully connect to the SMTP server and login. But I can't get the program working to send the email trough the SMTP server.
Here is a part of the original code that sends the email:
Code:
my $unique_order_id = "$last_id"."_"."$domainName";
my $cryptname = &crypt_key($unique_order_id);
# send an e-mail
open(FILE, "<$c{templates}/$c{default_lang}/confirm.tmpl") or print "Unable to open file '$c{templates}/$c{default_lang}/confirm.tmpl'. $!";
my $template = join('', <FILE>);
close(FILE);
$template =~ s/<Titl>/$title/g;
$template =~ s/<FirstName>/$firstName/g;
$template =~ s/<LastName>/$lastName/g;
$template =~ s/<CGI_BIN>/$c{cgi_bin}/g;
$template =~ s/<ConfirmCode>/confirm.cgi?id=$unique_order_id&key=$cryptname&action=confirm/g;
$template =~ s/<ConfirmLink>/confirm.cgi/g;
$template =~ s/<ID>/$unique_order_id/g;
$template =~ s/<Key>/$cryptname/g;
$template =~ s/<OrgName>/$c{orgname}/g;
$template =~ s/<OrgEmail>/$c{orgmail}/g;
open(MAIL, "|$c{mailprog} -i -t") or print "Can't start mail program. $!";
print MAIL "To: \"$firstName $lastName\" <$email>\n";
print MAIL "From: \"$c{orgname}\" <$c{orgmail}>\n";
print MAIL "Subject: $c{confirmation_email_subject}\n";
print MAIL "Content-Type: text/html; charset=\"iso-8859-1\"\n";
print MAIL "Content-Transfer-Encoding: 8bit\n";
print MAIL "$template";
print MAIL"\n\n";
close(MAIL);
&xpheader(3);
print qq|
<table border="0" cellspacing="0" cellpadding="0" width="500">
<tr>
<td align="center">Account authorization code has been sent to your email: <b>$email</b>
I have changed this to:
Code:
my $unique_order_id = "$last_id"."_"."$domainName";
my $cryptname = &crypt_key($unique_order_id);
# send an e-mail
open(FILE, "<$c{templates}/$c{default_lang}/confirm.tmpl") or print "Unable to open file '$c{templates}/$c{default_lang}/confirm.tmpl'. $!";
my $template = join('', <FILE>);
close(FILE);
$template =~ s/<Titl>/$title/g;
$template =~ s/<FirstName>/$firstName/g;
$template =~ s/<LastName>/$lastName/g;
$template =~ s/<CGI_BIN>/$c{cgi_bin}/g;
$template =~ s/<ConfirmCode>/confirm.cgi?id=$unique_order_id&key=$cryptname&action=confirm/g;
$template =~ s/<ConfirmLink>/confirm.cgi/g;
$template =~ s/<ID>/$unique_order_id/g;
$template =~ s/<Key>/$cryptname/g;
$template =~ s/<OrgName>/$c{orgname}/g;
$template =~ s/<OrgEmail>/$c{orgmail}/g;
my smtp;
$smtp = Net::SMTP_auth->new('72.29.*.*');
$smtp->auth('LOGIN', '***', '***');
$smtp->mail($ENV{USER});
$smtp->to('$email');
$smtp->data();
$smtp->datasend("To: \"$firstName $lastName\" <$email>\n");
$smtp->datasend("From: \"$c{orgname}\" <$c{orgmail}>\n");
$smtp->datasend("Subject: $c{confirmation_email_subject}\n");
$smtp->datasend("Content-Type: text/html; charset=\"iso-8859-1\"\n");
$smtp->datasend("Content-Transfer-Encoding: 8bit\n");
$smtp->datasend("$template");
$smtp->datasend("\n\n");
$smtp->dataend();
$smtp->quit;
&xpheader(3);
print qq|
<table border="0" cellspacing="0" cellpadding="0" width="500">
<tr>
<td align="center">Account authorization code has been sent to your email: <b>$email</b>
And I have added this at the top of the file:
Code:
use Net::SMTP_auth;
The script works fine with this code, but only i'm not recieving any email. There are also no error messages in the error log. The SMTP server I use works perfectly when I send meail from my home pc. Does somone know what i'm doing wrong?