From: Toby Rodwell on
I know the tile doesn't sound very Ruby-related but please bear with me!
In a Ruby script I make a system call to 'sendmail' to send text from a
file I've created from a Ruby string (I use sendmail because I don't
have and cannot easily get 'mail' or other gems added to this machine).

All works fine until I try to to include semi-colons at the end of each
lne of text, ie "....;\n", at which point sendmail considers these as
comments, ignores the "\n" newline cahracters, and everything gets
printed on one line. Looking at sendmails manual this seems to be
expeced behaviour but the odd thing is that if I manually write a test
file, with 'nano', then the mail is sent, with line breaks as desired,
no problem. I also tried a file created by another script (bash I
think) and that was also OK. It is almost as if "\n" is not working in
exactly the same way as a 'return' when writing a text file manually. I
also tried "...;\r" instead of "...;\n", with no effect.

Other wordings which had no effect were "...; \n" and "...;\n ".
Strangley, "...;\n\n" *did* work, but of course generated an extra blank
line, which I don't want!

Any help or advice appreciated.
--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Toby Rodwell wrote:
> I know the tile doesn't sound very Ruby-related but please bear with me!
> In a Ruby script I make a system call to 'sendmail' to send text from a
> file I've created from a Ruby string (I use sendmail because I don't
> have and cannot easily get 'mail' or other gems added to this machine).
>
> All works fine until I try to to include semi-colons at the end of each
> lne of text, ie "....;\n", at which point sendmail considers these as
> comments, ignores the "\n" newline cahracters, and everything gets
> printed on one line. Looking at sendmails manual this seems to be
> expeced behaviour

This is complete nonsense. Sendmail doesn't handle semicolons in mail
bodies any differently from any other characters.

If you post your actual ruby code, we can tell you what's wrong with it,
but it's certainly nothing to do with sendmail.

Probably the best way to do it is to start sendmail using IO.popen and
then write the message body to the pipe.
--
Posted via http://www.ruby-forum.com/.

From: Robert Klemme on
On 02.05.2010 08:58, Toby Rodwell wrote:
> I know the tile doesn't sound very Ruby-related but please bear with me!
> In a Ruby script I make a system call to 'sendmail' to send text from a
> file I've created from a Ruby string (I use sendmail because I don't
> have and cannot easily get 'mail' or other gems added to this machine).

There is net/smtp in the standard library.
http://ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/index.html

> All works fine until I try to to include semi-colons at the end of each
> lne of text, ie "....;\n", at which point sendmail considers these as
> comments, ignores the "\n" newline cahracters, and everything gets
> printed on one line.

What do you mean by "gets printed"? Last time I checked sendmail was an
MTA, and MTA's do not print emails.

> Looking at sendmails manual this seems to be
> expeced behaviour but the odd thing is that if I manually write a test
> file, with 'nano', then the mail is sent, with line breaks as desired,
> no problem. I also tried a file created by another script (bash I
> think) and that was also OK. It is almost as if "\n" is not working in
> exactly the same way as a 'return' when writing a text file manually. I
> also tried "...;\r" instead of "...;\n", with no effect.
>
> Other wordings which had no effect were "...; \n" and "...;\n ".
> Strangley, "...;\n\n" *did* work, but of course generated an extra blank
> line, which I don't want!
>
> Any help or advice appreciated.

How exactly do you invoke sendmail (command line arguments) and how do
you interact with it (writing to stdin, using IO redirection...)?

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
From: Toby Rodwell on
Robert Klemme wrote:
> There is net/smtp in the standard library.
> http://ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/index.html
>
Ah, very helpful and very useful, many thanks Robert. By using

Net::SMTP.start(my_mail_server) { |smtp| smtp.send_message
IO.read(my_dodgy_file), from_address, to_address }

... I'm getting the same result as before confirming your and Brian's
position that this is not related to Sendmail (so I must have misread
that 'sendmail' man page). I focused my attention on the file I'm
feeding into Sendmail, and whilst I don't pretend to understand it, I
find if I add two newlines ("\n\n") before my list of lines ending in
semicolons then it works as desired.

Plus, I now know how to quickly and easily send e-mail from Ruby without
relying on other programs - nice!
--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Toby Rodwell wrote:
> I focused my attention on the file I'm
> feeding into Sendmail, and whilst I don't pretend to understand it, I
> find if I add two newlines ("\n\n") before my list of lines ending in
> semicolons then it works as desired.

Ah. An E-mail message consists of headers and a body, and they are
separated by a blank line (see RFC 2822 for the full details)

So if you want to send an E-mail and don't want to specify any headers,
you need a blank line at the top. An E-mail like that is invalid, so
sendmail will add a minimal set of headers for you anyway (e.g. To: is
the recipient(s) you provided on sendmail command line, From: is the
user who submitted the message)

It's better to provide the headers explicitly, and if you use sendmail
-t then the recipients are taken from the To:/Cc:/Bcc: headers that you
provide, so you don't need to provide them on the sendmail command line.

Regards,

Brian.
--
Posted via http://www.ruby-forum.com/.