Newline problem 
Author Message
 Newline problem

Good Morning,

I have made a perl script which reads email addresses and Text Message to be
sent using Net::SMTP.

The input file is a simple text file with "NAME<TAB>Message\n" format...i.e
Name and Messages are tab seperated and each record is in a newline.
My code does $smtp->datasend("$message") but I can't figure out a way to put
newlines in the email.

For eg, consider the message being as:
Hello ABC,\n Nice to Meet you.\nRegards,\nXYZ.

I want this to appear in email as :
Hello ABC,
Nice to Meet you.
Regards,
XYZ.

But I can't get these \n converted to newlines.
Where is the problem, scanning the data from text file or while sending the
email data?
How can I solve it?

TIA,
Kasp
--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
             -- Larry Wall



Wed, 28 Sep 2005 16:33:09 GMT  
 Newline problem

Quote:

> Good Morning,

> I have made a perl script which reads email addresses and Text Message to be
> sent using Net::SMTP.

> The input file is a simple text file with "NAME<TAB>Message\n" format...i.e
> Name and Messages are tab seperated and each record is in a newline.
> My code does $smtp->datasend("$message") but I can't figure out a way to put
> newlines in the email.

that oughta do it... let's see the real code...

--
Michael Budash



Wed, 28 Sep 2005 17:02:44 GMT  
 Newline problem
Here is the test input file called test.txt

abc 123\n456\n789
123 Make\nThe\n Newlines\nwork!!

Here is the code snippet:

open(IN_FILE,"test.txt") || die "Failed to open file .$!";
while(defined( $lineRead = <IN_FILE>) ) #Read one line at a time
{
chomp($lineRead);

#split line read based on TABS
($NAME, $MESSAGE) = split(/\t/, $lineRead);
sendMail( $MESSAGE);
print "Mail sent to $NAME";

Quote:
}

close(IN_FILE);

sub sendMail(){


use Net::SMTP;
$smtp = Net::SMTP->new(mailServer);


$smtp->data();
$smtp->datasend("Subject: Hi\n");

$smtp->datasend("\n");

$smtp->datasend("$message");

$smtp->dataend();
$smtp->quit;

Quote:
}

--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
             -- Larry Wall


Wed, 28 Sep 2005 18:13:30 GMT  
 Newline problem

Quote:

> I have made a perl script which reads email addresses and Text Message to
be
> sent using Net::SMTP.

> The input file is a simple text file with "NAME<TAB>Message\n"
format...i.e
> Name and Messages are tab seperated and each record is in a newline.
> My code does $smtp->datasend("$message") but I can't figure out a way to
put
> newlines in the email.

> For eg, consider the message being as:
> Hello ABC,\n Nice to Meet you.\nRegards,\nXYZ.

> I want this to appear in email as :
> Hello ABC,
> Nice to Meet you.
> Regards,
> XYZ.

> But I can't get these \n converted to newlines.
> Where is the problem, scanning the data from text file or while sending
the
> email data?
> How can I solve it?

use diagnostics;
use strict;

my $message = 'This is a\nmessage for\n you.\n';
print "\$message = $message\n";
(my $dmess = $message) =~ s/\\n/\n/g;

print "\$dmess = $dmess";

This should solve your problem.

HTH,

Jodyman



Wed, 28 Sep 2005 19:22:36 GMT  
 Newline problem

Quote:
> (my $dmess = $message) =~ s/\\n/\n/g;

Thanks for the help Jodyman, I got your $message ;-)

--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
             -- Larry Wall> print "\$message = $message\n";



Wed, 28 Sep 2005 20:20:18 GMT  
 Newline problem

Quote:

> I have made a perl script which reads email addresses and Text Message to be
> sent using Net::SMTP.

> The input file is a simple text file with "NAME<TAB>Message\n" format...i.e
> Name and Messages are tab seperated and each record is in a newline.
> My code does $smtp->datasend("$message") but I can't figure out a way to put
> newlines in the email.

> For eg, consider the message being as:
> Hello ABC,\n Nice to Meet you.\nRegards,\nXYZ.

> I want this to appear in email as :
> Hello ABC,
> Nice to Meet you.
> Regards,
> XYZ.

> But I can't get these \n converted to newlines.
> Where is the problem, scanning the data from text file or while sending the
> email data?
> How can I solve it?

Instead of using a tab character as the field separator and a newline as
the record separator create your own unique field and record separators:

$/ = "<RS>\n";

while ( <DATA> ) {
    my ( $name, $data ) = split /<FS>\n/;
    # do something with $name and $data here
    }

__DATA__

Hello ABC,
Nice to Meet you.
Regards,
XYZ.
<RS>

Hello ABC,
Nice to Meet you.
Regards,
XYZ.
<RS>

John
--
use Perl;
program
fulfillment



Wed, 28 Sep 2005 22:08:31 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. newline problem with messy output - v simple problem

2. newline problem with formatted write

3. format picture fields with newlines problem

4. MIME-Tools - MIME::Entity - extra newline problem

5. newline problem w/ CGI on NT

6. win32 newline problem

7. Replacing multiple occurences of newline chars with a single newline char

8. Strange problem with newline (\r\n) under Win32

9. Problem checking for newline in $_ input line

10. newlines and query -> param / problem with apostrophes

11. Easy regular expression problem - matching characters and newline at the same time

12. newline and carriage return problems

 

 
Powered by phpBB® Forum Software