Getting the Message-Id for an outgoing email

F

Francis Hwang

Anybody know how I can get the Message-Id that's assigned to an
outgoing message when I send by using the SMTP class? It looks like I
can set the Message-Id myself, so then I'll have it, but that seems
like a lot of work. It'd be just easier to let sendmail set it and get
it back.

Francis
 
W

why the lucky stiff

Francis said:
Anybody know how I can get the Message-Id that's assigned to an
outgoing message when I send by using the SMTP class? It looks like I
can set the Message-Id myself, so then I'll have it, but that seems
like a lot of work. It'd be just easier to let sendmail set it and get
it back.

Francis
This doesn't solve the problem the way you've asked, but perhaps it's
good enough. Have you scrutinized RubyMail? [1] It's really good.
I've had to gus around with e-mail quite a bit lately and this package
has cut my work in half.

So, here's the deal with it: it's a library for parsing e-mail, but you
can also generate new messages with it. It has an add_message_id method
in the RMail::Header class that will generate new message IDs for you.

msg = RMail::Message.new
msg.header['To'] = '(e-mail address removed)'
msg.header['From'] = '(e-mail address removed)'
msg.body = 'I like you sooo much. Come have soda!'
msg.header.add_message_id

msg_id = mail.header.message_id
Net::SMTP.start( 'localhost' ) do |smtp|
smtp.send_message( msg.to_s, msg.header['From'], msg.header['To'] )
end

Something like that. Haven't tested that last part, but forage thru the
docs. [2] Start with 'guide/Intro.txt'.

_why

[1] http://www.lickey.com/rubymail/
[2] http://www.lickey.com/rubymail/rubymail/doc/
 
F

Francis Hwang

That solution probably would've worked, except I've already got a
bunch of code that looks a lot like that anyway and switching would've
been a pain. I ended up just implementing it myself following Jamie
Zawinski's recommendations at http://www.jwz.org/doc/mid.html .

Francis

why the lucky stiff said:
Francis said:
Anybody know how I can get the Message-Id that's assigned to an
outgoing message when I send by using the SMTP class? It looks like I
can set the Message-Id myself, so then I'll have it, but that seems
like a lot of work. It'd be just easier to let sendmail set it and get
it back.

Francis
This doesn't solve the problem the way you've asked, but perhaps it's
good enough. Have you scrutinized RubyMail? [1] It's really good.
I've had to gus around with e-mail quite a bit lately and this package
has cut my work in half.

So, here's the deal with it: it's a library for parsing e-mail, but you
can also generate new messages with it. It has an add_message_id method
in the RMail::Header class that will generate new message IDs for you.

msg = RMail::Message.new
msg.header['To'] = '(e-mail address removed)'
msg.header['From'] = '(e-mail address removed)'
msg.body = 'I like you sooo much. Come have soda!'
msg.header.add_message_id

msg_id = mail.header.message_id
Net::SMTP.start( 'localhost' ) do |smtp|
smtp.send_message( msg.to_s, msg.header['From'], msg.header['To'] )
end

Something like that. Haven't tested that last part, but forage thru the
docs. [2] Start with 'guide/Intro.txt'.

_why

[1] http://www.lickey.com/rubymail/
[2] http://www.lickey.com/rubymail/rubymail/doc/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top