Results 1 to 8 of 8
  1. #1

    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?

  2. #2
    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. #3
    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]#

  4. #4
    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. #5
    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. #6
    Join Date
    Jan 2005
    Location
    UK
    Posts
    1,370
    I think you can set it to debug mode so you can see what is going on. You may want to try that.

  7. #7

    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. #8
    I found the problem. I forgot the $ in my $smtp; !!! (thanks to the debug mode )
    Thanks for the help!

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •