Peña, Botp
8/9/2008 4:36:00 AM
From: Daniel Berger [mailto:djberg96@gmail.com]=20
#DB: require 'net/smtp'
#DB: mhost =3D 'mailgate.work.com'
#DB: from =3D 'daniel.berger@work.com'
#DB: # First email is valid, second one is not
#DB: to =3D ['daniel.berger@work.com', 'foo.bar@work.com']
#DB:=20
#DB: # Raises a Net::SMTPFatalError
NO, it should not (unless you reached the limit of the server's max =
recipient setting). what are the details of the error?
#DB: Net::SMTP.start(mhost, 25){ |smtp|
#DB: smtp.send_message("hello", from, to)
#DB: }
below is the actual code i used, adapted fr your code. i just modified =
the params to work in my case and put some debugging so i know where in =
the smtp session a certain error occurred just in case. i also show an =
actual run. result is that i got one email for the test and another =
bounced email for the dummy foo.bar address.
C:\family\ruby\mail>cat daniel.rb
require 'rubygems'
require 'net/smtp'
smtp_server =3D 'bugomail.delmonte-phil.com'
smtp_port =3D 25
from =3D 'botp@bugo.dmpi'
# First email is valid, second one is not
to =3D ['botp@bugo.dmpi', 'foo.bar@bugo.dmpi']
# Raises a Net::SMTPFatalError
smtp =3D Net::SMTP.new(smtp_server, smtp_port)
smtp.set_debug_output $stderr # use for debugging; outputs mail =
sessions
smtp.start { |smtp|
smtp.send_message("this is a test", from, to)
}
C:\family\ruby\mail>ruby daniel.rb
Connection opened: bugomail.delmonte-phil.com:25
-> "220 BUGOMAIL.delmonte-phil.com Microsoft ESMTP MAIL Service, =
Version: 6.0.37
90.3959 ready at Sat, 9 Aug 2008 12:24:50 +0800 \r\n"
<- "EHLO localhost.localdomain\r\n"
-> "250-BUGOMAIL.delmonte-phil.com Hello [10.2.10.123]\r\n"
-> "250-TURN\r\n"
-> "250-SIZE\r\n"
-> "250-ETRN\r\n"
-> "250-PIPELINING\r\n"
-> "250-DSN\r\n"
-> "250-ENHANCEDSTATUSCODES\r\n"
-> "250-8bitmime\r\n"
-> "250-BINARYMIME\r\n"
-> "250-CHUNKING\r\n"
-> "250-VRFY\r\n"
-> "250-X-EXPS GSSAPI NTLM LOGIN\r\n"
-> "250-X-EXPS=3DLOGIN\r\n"
-> "250-AUTH GSSAPI NTLM LOGIN\r\n"
-> "250-AUTH=3DLOGIN\r\n"
-> "250-X-LINK2STATE\r\n"
-> "250-XEXCH50\r\n"
-> "250 OK\r\n"
<- "MAIL FROM:<botp@bugo.dmpi>\r\n"
-> "250 2.1.0 botp@bugo.dmpi....Sender OK\r\n"
<- "RCPT TO:<botp@bugo.dmpi>\r\n"
-> "250 2.1.5 botp@bugo.dmpi \r\n"
<- "RCPT TO:<foo.bar@bugo.dmpi>\r\n"
-> "250 2.1.5 foo.bar@bugo.dmpi \r\n"
<- "DATA\r\n"
-> "354 Start mail input; end with <CRLF>.<CRLF>\r\n"
writing message from String
wrote 19 bytes
-> "250 2.6.0 <BUGOMAIL017ddhlHs4600000010@BUGOMAIL.delmonte-phil.com> =
Queued ma
il for delivery\r\n"
<- "QUIT\r\n"
-> "221 2.0.0 BUGOMAIL.delmonte-phil.com Service closing transmission =
channel\rn"
C:\family\ruby\mail>
#DB: If this is the wrong approach, I'm all ears.
that approach is fine for small number of recipients. generally, mail =
servers limit the number of recipients of a single mail.=20
So, for a big number (we do not care how many),=20
I. use a loop
Net::SMTP.start(mhost, 25){ |smtp|
to.each do |recipient|
smtp.send_message("hello", from, recipient)
end
end
II. or send to a mail_group address to the mail server configured w the =
aliases, ie mail_group =3D> user1@test.com, user2@test2.com, ....
III. or send to a mail_group address to a mail server capable of routing =
it to a mailing list server (eg majordomo). this is the ideal setup for =
big lists.=20
kind regards -botp