# Getting Net/SMTP to work for me

**URL:** <https://www.ruby-forum.com/t/getting-net-smtp-to-work-for-me/63491>\
**Category:** Ruby\
**Created:** [June 15, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/getting-net-smtp-to-work-for-me/63491 "2006-06-15T18:11:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [June 15, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/getting-net-smtp-to-work-for-me/63491/1 "2006-06-15T18:11:03Z")

</div>

I’ve managed to get a simple mail message sent to myself, but, it leaves  
a lot to be desired. I get an e-mail from my server, to me, but, there’s  
no body to the mail, even though I created some message text in a  
“message” variable. Also, in the e-mail sent to me, the “to” field in  
the e-mail is blank, with my e-mail address under cc: as a blind copy,  
(bcc: Peter B./BNA Inc). Can someone help me put in a subject line,  
and, get my timestamp to work as my e-mail body? And, I need to put the  
name of the file that I’m telling people about in the subject line, too.  
That’s in a variable.

(1) message = “Time Sent: ‘Time.now’”  
(2) Net::SMTP.start(‘notes1’, 25) do |smtp|  
(3) smtp.send\_message message,  
(4) ‘removed\_email\_address@domain.invalid’,  
(5) ‘removed\_email\_address@domain.invalid’  
end

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [June 15, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/getting-net-smtp-to-work-for-me/63491/2 "2006-06-15T19:51:26Z")

</div>

Peter B. wrote:

> (1) message = “Time Sent: ‘Time.now’”  
> (2) Net::SMTP.start(‘notes1’, 25) do |smtp|  
> (3) smtp.send\_message message,  
> (4) ‘removed\_email\_address@domain.invalid’,  
> (5) ‘removed\_email\_address@domain.invalid’  
> end
> 
> Thanks for any help.

Hi Peter,

Please see the Net/SMTP documentation [1]. It gives you an example of a  
message. Things like the ‘to’ and ‘from’ addresses all go in the  
message.

Here’s a simpler example (untested):

message = \<\<EOS  
From: Bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: Someone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Hi There!

Hi Someone,

How’s it going?

Love,  
Bob  
EOS

require ‘net/smtp’  
Net::SMTP.start(‘your.smtp.server’, 25) do |smtp|  
smtp.send\_message(message, ‘removed\_email\_address@domain.invalid’, ‘removed\_email\_address@domain.invalid’)  
end

Hope that helps.

-Justin

[1][http://ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/classes/Net/SMTP.html](http://ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/classes/Net/SMTP.html)

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [June 15, 2006, 10:25pm UTC](https://www.ruby-forum.com/t/getting-net-smtp-to-work-for-me/63491/3 "2006-06-15T22:25:08Z")

</div>

Justin C. wrote:

> > 
> 
> Hi Peter,  
> Subject: Hi There!  
> Net::SMTP.start(‘your.smtp.server’, 25) do |smtp|  
> [1][http://ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/classes/Net/SMTP.html](http://ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/classes/Net/SMTP.html)

If you install RubyMail or TMail via gems, you will need to require  
‘rubygems’ as well as ‘rmail’ or ‘tmail’. Both of those are good tools,  
but there is also MailFactory, which is easy to use:

require ‘mailfactory’

```
    mail = MailFactory.new()
    mail.to = "removed_email_address@domain.invalid"
    mail.from = "Internet D. <removed_email_address@domain.invalid>"
    mail.subject = "My, what big ears you have!"
    mail.text = "Have you ever considered plastic surgery?"

    Net::SMTP.start('localhost',25, 'otherserver.myorg.org',

```

‘removed\_email\_address@domain.invalid’, “$Uper$ecret”, :login) { |smtp|  
smtp.send\_message(mail.to\_s, “removed\_email\_address@domain.invalid”,  
“removed\_email\_address@domain.invalid”)  
}
