hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Email trough smtp server.
Reply

Forum Jump

Email trough smtp server.

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-08-2005, 07:51 AM
johnnygo johnnygo is offline
Newbie
 
Join Date: Jun 2005
Posts: 12

Email trough smtp server.


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?



Sponsored Links
  #2  
Old 09-08-2005, 07:04 PM
jetson jetson is offline
Junior Guru Wannabe
 
Join Date: Sep 2005
Posts: 57
what happens when you do this from the cgi host?
Try to emulate the same addresses used in the script version

Code:
>telnet mail.example.com 25

>HELO example.com

>MAIL FROM from@example.com

>RCPT TO to@example.com

>DATA

>this is a test
>.

>quit

  #3  
Old 09-09-2005, 03:57 AM
johnnygo johnnygo is offline
Newbie
 
Join Date: Jun 2005
Posts: 12
jetson, thanks for your answer. I tried your code, but I get some errors. See the result:

Code:
[root@free1 root]# telnet 72.29.*.* 25
Trying 72.29.*.*...
Connected to 72-29-*-*.****.com (72.29.*.*).
Escape character is '^]'.
220-server.***.*** ESMTP Exim 4.52 #1 Fri, 09 Sep 2005 09:37:51 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
HELO free1.****.***
250 server.****.*** Hello free1.****.*** [72.29.*.*]
MAIL FROM support@******.com
500 unrecognized command
RCPT TO john@*****.cc
500 unrecognized command
DATA this is a test
501-unexpected argument data
501 Too many syntax or protocol errors
Connection closed by foreign host.
[root@free1 root]#

Sponsored Links
  #4  
Old 09-09-2005, 04:16 AM
Slidey Slidey is offline
Web Hosting Master
 
Join Date: Apr 2003
Location: UK
Posts: 2,560
hi

the error is caused because you are missing colons : after the mail from and rcpt to arguments/commands

the correct way to do it is

mail from: support@domain.com
rcpt to: user@domain2.com

eg:

mail from andy@test.com
501 Syntax: MAIL FROM: <address>

  #5  
Old 09-09-2005, 05:38 AM
johnnygo johnnygo is offline
Newbie
 
Join Date: Jun 2005
Posts: 12
Ok, that is working better. Only, I have to login to the smtp server. I recieve the folloing message when I try to send the email.
Code:
550 Administrative prohibition
Thats the reason why I try to use Net:MTP_auth.

  #6  
Old 09-09-2005, 11:57 AM
BizWyse BizWyse is offline
Web Hosting Master
 
Join Date: Jan 2005
Location: USA
Posts: 1,353
I think you can set it to debug mode so you can see what is going on. You may want to try that.

  #7  
Old 09-10-2005, 04:49 AM
johnnygo johnnygo is offline
Newbie
 
Join Date: Jun 2005
Posts: 12
Question

Finally I got an error message in the error log But now I also receive an 500 error when executing the script.

I got this from the error log:

Code:
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] No such class smtp at /home/***/cgi-bin/registertest.cgi line 1203, near "my smtp"
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] syntax error at /home/***/cgi-bin/registertest.cgi line 1203, near "my smtp;"
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1204.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1207.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1209.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1210.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1212.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1213.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1214.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1215.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1216.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1217.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1218.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1219.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1220.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1222.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Execution of /home/***/cgi-bin/registertest.cgi aborted due to compilation errors.
[Sat Sep 10 01:20:42 2005] [error] [client 84.30.48.*] Premature end of script headers: registertest.cgi
The first error here is with
Code:
my smtp;
So I removed this. But now I recieve the folloing error.

Code:
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1204.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1207.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1209.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1210.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1212.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1213.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1214.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1215.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1216.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1217.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1218.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1219.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1220.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Global symbol "$smtp" requires explicit package name at /home/***/cgi-bin/registertest.cgi line 1222.
[Sat Sep 10 01:33:17 2005] [error] [client 84.30.48.*] Execution of /home/***/cgi-bin/registertest.cgi aborted due to compilation errors.
I have no idea what this means, and how I can fix it.

  #8  
Old 09-10-2005, 07:59 AM
johnnygo johnnygo is offline
Newbie
 
Join Date: Jun 2005
Posts: 12
I found the problem. I forgot the $ in my $smtp; !!! (thanks to the debug mode )
Thanks for the help!

Reply

Related posts from TheWhir.com
Title Type Date Posted
Open-Xchange Launches Tool to Encrypt Online Communications Web Hosting News 2014-09-03 10:43:43
As STARTTLS Adoption Grows, Facebook Reports Huge Jump in Encrypted Notification Emails Web Hosting News 2014-08-20 14:01:32
Security Experts Refute German Email Security Firms Secure Data Storage Claim Web Hosting News 2013-08-13 16:24:48
Microsoft Sees Largest Gain in Host Names in December 2012 Netcraft Web Server Survey Web Hosting News 2012-12-05 13:38:09
Atmail Email Tools Get Boost from $2 Million Investment in Growth Web Hosting News 2012-11-21 14:25:41


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?