• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

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

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
tsr50
Asked:
tsr50
  • 2
1 Solution
 
biglugCommented:
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
 
biglugCommented:
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
 
fuzzyfluidCommented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now