Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Can't get an email message to format properly... Linefeeds not working?

by NeilF (Sexton)
on Jan 19, 2006 at 22:32 UTC ( #524364=perlquestion: print w/replies, xml ) Need Help??

NeilF has asked for the wisdom of the Perl Monks concerning the following question:

I've got a simple routine to fire out emails. I noticed with some calls the mails appeared as expected, but with others the linefeeds were not working. Instead of appearing on a new line there'd just be a space and then the text.

When this happens in Outlook you can enable/disable "Wrap" and the message will appear correctly/incorrectly.

There's something here I don't understand, and hope someone can point out what's going wrong.

The following example sends out two emails, one with double linefeeds and one with single linefeeds. The one with double linefeeds behaves as expected. The one with single line feeds does not!
#!/usr/bin/perl # Choice method of sending, sendmail or SMTP $mail_prog='smtp:mail.MYWEBSITE.com'; #$mail_prog="/usr/sbin/sendmail"; $addr_to="neil\@MYEMAIL.com"; $addr_from="hi\@MYEMAIL.com"; $|=1; print "Content-type:text/html;charset=ISO-8859-1\n\n<pre>"; print "Mail Test program...\n"; # Get a blank line between each line (as expected) $rest_of_msg="Subject:This is a subject\n\n"; $rest_of_msg.="A reply has been posted to your message on the website +blah blah blah.\n\n"; $rest_of_msg.="The URL for the response is\n\n"; $rest_of_msg.="http://www.awebsite.com/cgi/software/program.pl?f=1&m=2 +54388&df=1\n\n"; &send_an_email($addr_to,$addr_from,$rest_of_msg); # Doesn't do any line feeds! $rest_of_msg="Subject:This is a subject\n\n"; $rest_of_msg.="A reply has been posted to your message on the website +blah blah blah.\n"; $rest_of_msg.="The URL for the response is\n"; $rest_of_msg.="http://www.awebsite.com/cgi/software/program.pl?f=1&m=2 +54388&df=1\n"; &send_an_email($addr_to,$addr_from,$rest_of_msg); print "Sent!"; exit; sub send_an_email{ my($to,$from,$rest)=@_; if(substr($mail_prog,0,5) eq 'smtp:'){ require Net::SMTP; my $smtp=substr($mail_prog,5); $smtp = Net::SMTP->new($smtp); $smtp->mail($from); $smtp->to($to); $smtp->data(); $smtp->datasend("To:$to\nFrom:$from\n$rest"); $smtp->dataend(); $smtp->quit(); }else{ open MAIL,"|$mail_prog -t"; print MAIL "To:$to\nFrom:$from\n$rest"; close MAIL; } }

The two emails I get appear line this:-
A reply has been posted to your message on the website blah blah blah. The URL for the response is http://www.awebsite.com/cgi/software/program.pl?f=1&m=254388&df=1

A reply has been posted to your message on the website blah blah blah. The URL for the response is http://www.awebsite.com/cgi/software/program.pl?f=1&m=254388&df=1

Like I say some emails I send appear absolutely fine so I'm not sure if length of lines play some part in it working? But something very odd is going on!?

Replies are listed 'Best First'.
Re: Can't get an email message to format properly... Linefeeds not working?
by clinton (Priest) on Jan 20, 2006 at 00:34 UTC
    It probably has something to do with the fact that line terminators in SMTP (see RFC) are supposed to be \r\n, so the client is managing to interpret \n\n to represent what you meant to express, but it is working in 'quirks mode'.

    hth clint

      OK cheers! I'll try that... I did try SENDMAIL as well...
      DID NOT WORK! \r\n still does not force a new line...

      It appears like this in outlook:-

      A reply has been posted to your message on the website blah blah blah. The URL for the response is
      http://www.awebsite.com/cgi/software/program.pl?f=1&m=254388&df=1

      Note: The URL is on a new line but may just have autowrapped.
        It's actually a problem/issue with Outlook 2003!!!!

        http://www.masternewmedia.org/newsletter_publishing/newsletter_formatting/remove_line_breaks_issue_Microsoft_Outlook_2003_when_publishing_text_newsletters_20051217.htm

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://524364]
Approved by ysth
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-05-22 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?