?
Solved

Net::SMTP works, but when u try to reply Error occurs

Posted on 2003-03-18
3
Medium Priority
?
156 Views
Last Modified: 2010-03-05
I can successfully send an email using Net:SMTP, but the receipient isn't able to reply.  The from header is only a string and not connect to any email.  When I send the email though I want just the string to be display.
Here is my code and thanks for any help
use Net::SMTP;
  my $sender = Net::SMTP->new ('mailhost');
  $sender->mail('joe@somewhere.com);
  $sender->to ('bob@somewhere.com);
  $sender->data();
  $sender->datasend ("From:  Joe\n");
  $sender->datasend ("To:  Bob\n");
  $sender->datasend ("Test\n");
  $sender->datasend ("\n");
  $sender->datasend ("Please Work");
  $sender->dataend();
  $sender->quit();
0
Comment
Question by:tsr50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Expert Comment

by:biglug
ID: 8161971
First, the above code contains syntax errors ... you need to close the quotes after the email addresses ...

Second, Net::SMTP probably isn't the best module to be using here .. try something like Mail::Send or Mail::Sendmail or Mail::Sender or ... they have a friendlier interface IIRC.


BUT, to answer your question, you need to declare your to and from addresses in the headers you supply:

 use Net::SMTP;
 my $sender = Net::SMTP->new ('mailhost');
 $sender->mail('joe@somewhere.com');
 $sender->to ('bob@somewhere.com');
 $sender->data();
 $sender->datasend ("From:  Joe <joe@somewhere.com>\n");
 $sender->datasend ("To:  Bob <bob@somewhere.com>\n");
 $sender->datasend ("Test\n");
 $sender->datasend ("\n");
 $sender->datasend ("Please Work");
 $sender->dataend();
 $sender->quit();
0
 
LVL 1

Accepted Solution

by:
biglug earned 880 total points
ID: 8161996
Oops .. I should point out that I had to change the gap between the 'To:' and 'Bob...' to a single space. Hmm .. just noticed another error:

use Net::SMTP;
my $sender = Net::SMTP->new ('mailhost');
$sender->mail('joe@somewhere.com');
$sender->to ('bob@somewhere.com');
$sender->data();
$sender->datasend ("Subject: This will work\n");
$sender->datasend ("From: Joe <joe@somewhere.com>\n");
$sender->datasend ("To: Bob <bob@somewhere.com>\n\n"); #need to end the headers with a double newline.
$sender->datasend ("Test\n"); #otherwise this looks like a header
$sender->datasend ("\n"); #and this looks like the double newline
$sender->datasend ("Please Work");
$sender->dataend();
$sender->quit();

0
 

Expert Comment

by:fuzzyfluid
ID: 8188064
remember, you have to use mail.blahblah.com to send mail. it may be mail.blahblah.com ,or smtp.blahblah.com. Better than simply using mailhost.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question