andersonsm1 Posted January 30, 2005 Posted January 30, 2005 Greetings, I've been working on a Perl script to send email from my home computer to an email account using my domain's SMTP server. The script is: >#!/usr/bin/perl -w use Net::SMTP; use Net::SMTP::SSL; my $server_name = "mail.****"; $smtp = Net::SMTP::SSL->new($server_name, Timeout => 30, Debug =>1, Port=>465); $smtp->auth('username+****', 'password'); my $mail_from = "user\@****"; my $mail_to = "target\@targetdomain.com"; $smtp->mail( $mail_from ); $smtp->recipient( $mail_to ); $smtp->data(); $smtp->datasend("To: target\@targetdomain.com"); $smtp->datasend("From: user\@****"); $smtp->datasend("Subject: Test from Perl\n"); $smtp->datasend("\n"); $smtp->datasend("This is a test message from Perl.\n"); $smtp->dataend(); $smtp->quit(); When run, the following output is generated: ><<< 220-server29.totalchoicehosting.com ESMTP Exim 4.44 #1 Sun, 30 Jan 2005 11:17:24 -0600 <<< 220-We do not authorize the use of this system to transport unsolicited, <<< 220 and/or bulk e-mail. >>> EHLO localhost.localdomain <<< 250-server29.totalchoicehosting.com Hello localhost.localdomain [xx.xxx.xxx.xxx] <<< 250-SIZE 52428800 <<< 250-PIPELINING <<< 250-AUTH PLAIN LOGIN <<< 250 HELP >>> AUTH PLAIN c2NvdHQrc2NvdHRhbmRqdWxpZWFuZGVyc29uLmNvbQBzY290dCtzY290dGFuZGp1bGllYW5kZXJzb24uY29tA Z1enp5bnV0cw== <<< 235 Authentication succeeded >>> MAIL FROM:<user@****> <<< 250 OK >>> RCPT TO:<target@targetdomain.com> <<< 250 Accepted >>> DATA <<< 354 Enter message, ending with "." on a line by itself >>> To: target@targetdomain.com >>> From: user@**** >>> Subject: Test from Perl >>> This is a test message from Perl. >>> . <<< 550 Administrative prohibition >>> QUIT <<< 221 server29.totalchoicehosting.com closing connection Any ideas why exim is closing the connection? I appear to have authenticated properly with the system. Also, I can use SSL on port 465 and send email successfully using MS Outlook. Your help is appreciated---thanks! Quote
borfast Posted January 30, 2005 Posted January 30, 2005 Anderson, I don't think I have welcomed you to the family, so... welcome aboard! As for the problem you're experiencing, that's probably due to the fact that TCH sets the mail servers' security to not allow spammers to use them as relays. I'm not 100% sure about this but logging in via SMTP should be enough to prevent that but I do know that sometimes, ISPs force people to log in to their POP3 accounts before allowing them to use SMTP to send messages, so perhaps if you login into your POP account before logging into SMTP will do the trick. Also, here's a suggestion: Although completely possible, it's not usual to use Perl under a Windows environment (and even less to code scripts), so assuming you're using some form of Unix operating system, why don't you install Sendmail and use it to send e-mail? Quote
andersonsm1 Posted January 30, 2005 Author Posted January 30, 2005 Raul, Thanks for the quick reply! I've been a very happy TCH customer for about a year and a half now. Your point regarding using Sendmail is well taken---I am using this script on Linux and I was looking for a quick solution (and I didn't want to learn or have to worry about Sendmail). I will try to log into my POP account first and them send mail. Thanks for your help and I'll let you know how it goes. Quote
borfast Posted January 30, 2005 Posted January 30, 2005 Depending on your Linux distribution, there may be some pre-configured packages available. For instance, I use Fedora Core and it has Sendmail all ready to go. I use it as the default mail delivery method most of the time. Also, using it is really really simple, there are lots of tutorials around on the web, so if you decide to go that way, it won't be that hard, don't worry Anyway, good luck and let me know how it goes Quote
andersonsm1 Posted January 31, 2005 Author Posted January 31, 2005 I found an error in my script which prevented me from sending mail through TCH: Original Code: >$smtp->datasend("To: target\@targetdomain.com"); $smtp->datasend("From: user\@****"); $smtp->datasend("Subject: Test from Perl\n"); Each header must be followed by a newline. Correct Code: >$smtp->datasend("To: target\@targetdomain.com\n"); $smtp->datasend("From: user\@****\n"); $smtp->datasend("Subject: Test from Perl\n"); You can also do this in the From header >$smtp->datasend("From: \"Your Name\" <user\@****>\n"); to display your name instead of your email address. Headers followed by newlines is a must for TCH but I was able to send email (albeit a little jumbled...) through my ISP's SMTP server. This script makes use of Net::SMTP which has all sorts of other features like CC, BCC, and receipt request. Quote
TCH-Don Posted January 31, 2005 Posted January 31, 2005 Welcome to the Family Anderson and your new home! glad you worked out and yes thanks for the update, you never know when it might help someone else in your family. We really are like family here. So if you need anything, just ask your new family! We love to help Quote
borfast Posted January 31, 2005 Posted January 31, 2005 Nice work, Anderson And thanks for the update By the way, I forgot to write this joke on my previous post: So you're using Linux... I see you have chosen to take the red pill, Mr. Anderson. Good choice. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.