I use Ruby net/smtp
require 'net/smtp'
I send mails using the following method:
Net::SMTP.start(SMTP_SERVER) do |smtp|
smtp.send_message(message,"mailman-ruby@example.de",reciepent)
end
I want to add a subject to the mails i send but couldn't find one in the documentation.
What I tried so far is putting the subject into the message like this:
<<END_OF_MESSAGE
Subject: test message
. . . rest of the message
END_OF_MESSAGE
Unfortunally that doesnt do the trick!
Anyone knows how to set subject using 'smtp/net'?
The responsibility of the subject is not that of the SMTP protocol. It is held in one of the SMTP commands, which is to say
DATA
and as such, is not relevant in responsibility to that library.However, the
DATA
will contain either proper (specification indicated) headers, or even some headers that are not specified, but not disallowed. PGPAccording to RFC 5321 (and as expected) "Server SMTP systems SHOULD NOT reject messages based on perceived defects in the RFC 822 or MIME (RFC 2045 [21]) message header section or message body.".
So, your answer is going to be: "You don't set the subject by using that." But you would set the DATA with that information in it.
And the documentation that you linked to has an example of doing exactly that:
Documentation not linked here, as you have already provided the link.
net/smtp
is a very low-level library. It expects themessage
to be an email message, including all the headers.From the documentation
In your case, make sure to add a new line between the Headers and the body. Change
to
Instead of using
net/smtp
, I highly encourage you to usemail
.mail
uses a more high level interface for sending email messages without loosing the control of the message.If you don't really care about advanced usage, you can also switch to
pony
.