# Net/smtp question

**URL:** <https://www.ruby-forum.com/t/net-smtp-question/114529>\
**Category:** Ruby\
**Created:** [September 14, 2007, 6:11am UTC](https://www.ruby-forum.com/t/net-smtp-question/114529 "2007-09-14T06:11:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [September 14, 2007, 6:11am UTC](https://www.ruby-forum.com/t/net-smtp-question/114529/1 "2007-09-14T06:11:34Z")

</div>

Ive tried several examples from numerous books trying to send mail with  
net smtp and i never really get the emails.

require ‘net/smtp’

message = \<\<MESSAGE\_END  
From: Nobody [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: Test SMTP

i pray that itll work  
MESSAGE\_END

Net::SMTP.start(‘[mx1.hotmail.com](http://mx1.hotmail.com)’) do |smtp|  
smtp.send\_message message, ‘removed\_email\_address@domain.invalid’, ‘removed\_email\_address@domain.invalid’  
end

##### 

This was one example, i receive no errors indicating a problem but when  
checking my email IE: removed\_email\_address@domain.invalid i dont have it in any  
folders, not inbox or junkmail.

Another version that i modified to fit my own needs was this ----

require ‘net/smtp’

puts "Sender: "  
sender = gets.chomp  
puts "Recipient: "  
rcpt = gets.chomp  
puts "Message: "  
msg = gets.chomp

smtp = Net::SMTP.new(‘[mx1.hotmail.com](http://mx1.hotmail.com)’)

smtp.start()

smtp.ready(sender, rcpt) do |mail|

mail.write msg

end

#########  
once again no errors

any ideas why i might not be getting the emails?

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [September 17, 2007, 7:48am UTC](https://www.ruby-forum.com/t/net-smtp-question/114529/2 "2007-09-17T07:48:38Z")

</div>

Michael L. wrote:

> Ive tried several examples from numerous books trying to send mail with  
> net smtp and i never really get the emails.
> 
> require ‘net/smtp’
> 
> message = \<\<MESSAGE\_END  
> From: Nobody [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: Test SMTP
> 
> i pray that itll work  
> MESSAGE\_END
> 
> Net::SMTP.start(‘[mx1.hotmail.com](http://mx1.hotmail.com)’) do |smtp|  
> smtp.send\_message message, ‘removed\_email\_address@domain.invalid’, ‘removed\_email\_address@domain.invalid’  
> end

This example works perfectly good for me.

I would chack if server ‘[mx1.hotmail.com](http://mx1.hotmail.com)’ allows message relaying.

by  
TheR

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/net-smtp-question/114529/3 "2007-09-17T13:23:35Z")

</div>

From: Michael L. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# smtp = Net::SMTP.new(‘[mx1.hotmail.com](http://mx1.hotmail.com)’)

# smtp.start()

smtp.set\_debug\_output $stderr # insert this and email back the result

# smtp.ready(sender, rcpt) do |mail|

# mail.write msg

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/net-smtp-question/114529/4 "2007-09-17T13:23:08Z")

</div>

On Sep 17, 2007, at 12:48 AM, Damjan R. wrote:

> > Subject: Test SMTP
> 
> I would chack if server ‘[mx1.hotmail.com](http://mx1.hotmail.com)’ allows message relaying.

Agreed… meaning, in your example you are assuming that  
[mx1.hotmail.com](http://mx1.hotmail.com) is allowing un-authenticated SMTP. Majority of mail  
server require that you perform SMTP Auth before any outgoing  
transmission can occur.

Confidentiality Notice: This e-mail message (including any attached or  
embedded documents) is intended for the exclusive and confidential use  
of the  
individual or entity to which this message is addressed, and unless  
otherwise  
expressly indicated, is confidential and privileged information of  
Rackspace  
Managed Hosting. Any dissemination, distribution or copying of the  
enclosed  
material is prohibited. If you receive this transmission in error,  
please  
notify us immediately by e-mail at removed\_email\_address@domain.invalid, and delete the  
original message. Your cooperation is appreciated.

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/net-smtp-question/114529/5 "2007-09-17T13:24:58Z")

</div>

Michael L. wrote:

> i pray that itll work
> 
> #########  
> once again no errors
> 
> any ideas why i might not be getting the emails?

Does hotmail even allow SMTP usage? I noticed you were trying to connect  
to the server [mx1.hotmail.com](http://mx1.hotmail.com). Try this with a GMail account or other  
account, it should work. The following is part of a script that worked  
for me, though I haven’t tested it in 6 months. Ruby 1.8 doesn’t support  
TLS, so I had to require a file “smtp\_tls.rb” that you can find on the  
web. You won’t need it if your server doesn’t require TLS.

#!/usr/bin/env ruby  
require ‘net/smtp’  
require ‘smtp\_tls’

myMessage = \<\<END\_OF\_MESSAGE  
From: XXXXXXX [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: XXXXXX [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: XXXXX XXXXXX

This e-mail is a test.  
END\_OF\_MESSAGE

Net::SMTP.start(‘[smtp.gmail.com](http://smtp.gmail.com)’, 587, ‘localhost.localdomain’,  
username, password, :login) do |smtp|  
smtp.send\_message(myMessage, ‘removed\_email\_address@domain.invalid’,  
[‘removed\_email\_address@domain.invalid’]);

end

**END**

Good luck,  
Dan

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/net-smtp-question/114529/6 "2007-09-17T13:24:36Z")

</div>

Michael L. wrote:

> i pray that itll work
> 
> #########  
> once again no errors
> 
> any ideas why i might not be getting the emails?

I know I’m not directly answering your question, but there’s a sample on  
my blog:  
[http://notepad.onghu.com/ruby](http://notepad.onghu.com/ruby)

I think it would be good for you to try to send it to some other email  
address, perhaps, you are missing some fields which make your mail look  
like spam and is being dropped by something along the way?

Cheers,  
Mohit.  
9/14/2007 | 12:49 PM.

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [September 25, 2007, 11:04pm UTC](https://www.ruby-forum.com/t/net-smtp-question/114529/7 "2007-09-25T23:04:32Z")

</div>

Quoth Mohit S. on Thursday 13 September 2007 09:49:49 pm:

> > folders, not inbox or junkmail.  
> > msg = gets.chomp
> 
> I think it would be good for you to try to send it to some other email  
> address, perhaps, you are missing some fields which make your mail look  
> like spam and is being dropped by something along the way?
> 
> Cheers,  
> Mohit.  
> 9/14/2007 | 12:49 PM.

A lot of ISPs block people from having mail servers on their local  
machines,  
as this is something zombie networks tend to do rather than joe idiot  
user.
