Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   PERL SMTP e-mail help (http://www.go4expert.com/forums/perl-smtp-e-mail-help-t11798/)

gdsoccer11 3Jul2008 00:12

PERL SMTP e-mail help
Hey all,

I've written a working smtp email script using the NET::SMTP module the only problem is that whenever I use a \n in the message body it fails to place it in the email. Here is the script:


use Data::Dumper;
use Net::SMTP;
use strict;

my $to = 'to';
my $from = 'your name';
my $subject = "subject";
my $greeting = "An error has occured";
my $message = "Error Stats: blah blah blah /n
                          more blah blah";
my $smtp = Net::SMTP->new('xxx.xxx.x.xxx');   
my $status = $smtp->recipient($to);
$smtp->datasend("From: $from\n");
$smtp->datasend("To: $to\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("Content-Type: text/html; charset=\"us-ascii\"\n");

now like I said that succesfull sends the e-mail if everything is filled in but none of my new lines (and I have like 6 of them) are showing up in the message body.

Any thoughts?

naveen 9Jul2008 23:58

Re: PERL SMTP e-mail help
I see that you've given content type to be text-html, in which case, the newline is defined by the <br> tag and not \n. For \n to be converted to a new line, you need the content type of the email to be set to text-plain.

Try it out and see if it makes any difference. The rest of your script looks fine.


pradeep 10Jul2008 00:48

Re: PERL SMTP e-mail help
or try this!

Code: perl

$message =~ s/\n/<br\/>/g;

But Naveen's suggestion is the best!

ballroot 14Oct2008 05:17

Re: PERL SMTP e-mail help
Thanks, works for me too.

All times are GMT +5.5. The time now is 16:07.