Forum: Ruby on Rails Rookie with ActionMailer

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jason P. (Guest)
on 2005-12-18 00:25
To start out I'll say that this is the first thing that I've ever built
that's been intended to programmatically send email.  I'm looking at
examples in AWR and also on the wiki.  I feel that I sort of have things
set up right but I'm getting an error I can't grok:

Net::SMTPFatalError in Home#email_list
550 5.7.1 Unable to relay for removed_email_address@domain.invalid

/app/controllers/home_controller.rb:34:in `email_list'
script/server:54

removed_email_address@domain.invalid is my email and is pulled from my database 
table

I'm set up like this:

Controller:

def email_list
 email = Email.find(:first)
 MailList::deliver_send_email(email)
end

Model:

class MailList < ActionMailer::Base
	def send_email(email)
		@recipients = email.address
		@from = 'removed_email_address@domain.invalid'
		@subject = 'thanks for entering the contest'
	end
end

Environment:

# Include your app's configuration here:

ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
   :address        => "mail.address.ca",
   :port           => 25,
   :domain         => "www.address.ca",
   :authentication => :login,
   :user_name      => "username",
   :password       => "password"}

so to me it looks like there is something wrong with sending in SMTP.
I'm not really familiar with much of this so I much appreciate advice.

Thanks,

Jason
Steven S. (Guest)
on 2005-12-18 00:46
(Received via mailing list)
Typically the address for outgoing mail would start with smtp, such
as smtp.address.ca.  Addresses beginning with mail are typically for
incoming mail (POP).  Also, you may or may not need authentication
for sending mail.
Jason P. (Guest)
on 2005-12-18 00:50
Steven S. wrote:
> Typically the address for outgoing mail would start with smtp, such
> as smtp.address.ca.  Addresses beginning with mail are typically for
> incoming mail (POP).  Also, you may or may not need authentication
> for sending mail.

Okay, I guess the other thing I forgot to note is that I am trying to
get this runnning on my Windows localhost with WebRICK. I am not even
aware whether or not I can send email in this fashion, is it possible to
run like this?
Steven S. (Guest)
on 2005-12-18 00:58
(Received via mailing list)
It should work as far as I know.  Also, you'll need the actual
address of an smtp server (not sure if address.ca was just an example
or an actual smtp server).
Jason P. (Guest)
on 2005-12-18 01:50
Steven S. wrote:
> It should work as far as I know.  Also, you'll need the actual
> address of an smtp server (not sure if address.ca was just an example
> or an actual smtp server).

I've done a bit of fiddling, I have my smtp server from the company that
is my cable internet provider: 'shawmail.vc.shawcable.net'

then I have all the other authorization stuff like username, password,
filled out correctly for what works with my email.

I am getting this error:

'533 5.7.1 AUTH command is not enabled.'
Steven S. (Guest)
on 2005-12-18 01:59
(Received via mailing list)
The smtp server mail not require authentication for sending mail.
Try changing your server_settings as follows and see what happens:

ActionMailer::Base.server_settings = {
:address => "shawmail.vc.shawcable.net",
:port => 25,
:domain => "???",
:authentication => :plain
}
Jason P. (Guest)
on 2005-12-18 02:17
Steven S. wrote:
> The smtp server mail not require authentication for sending mail.
> Try changing your server_settings as follows and see what happens:
>
> ActionMailer::Base.server_settings = {
> :address => "shawmail.vc.shawcable.net",
> :port => 25,
> :domain => "???",
> :authentication => :plain
> }

Okay awesome!  I got a single email address firing.  Now, I am trying to
pass the email variable as an array to the Email model that does the
sending.

controller

def email_list
   email = Email.find(:all)
   MailList::deliver_send_email(email)
end

model

class MailList < ActionMailer::Base
	def send_email(email)
		@recipients = email.address
		@from = 'removed_email_address@domain.invalid'
		@subject = 'thanks for signing up'
	end
end

but I get rails thinking it's a method

undefined method `address' for #<Array:0x372bc00>

I'm not sure the syntax to access the address field of my database
table.  It was working with one email address, but how do I package and
pass the array to the Mailer?
Jason P. (Guest)
on 2005-12-18 02:54
Update:

I got this working:

def email_list
   email = Email.find(:all)
   email.each { |address| MailList::deliver_send_email(address) }
end

but for some reason that doesn't feel like the proper rails way to do
it.  The docs say that @recipients can be an array, but I am having
trouble passing the array and then grabbing the column I want
('address')
Steven S. (Guest)
on 2005-12-18 03:08
(Received via mailing list)
I think it's looking for an array of strings as in:

   @recipients = ["removed_email_address@domain.invalid", 
"removed_email_address@domain.invalid"]

As an alternate solution, I believe you could pass the email array to
send_email (as your first example had it) and iterate over the array
there adding the address for each email to @recipients.
Jason P. (Guest)
on 2005-12-18 03:13
Steven S. wrote:
> I think it's looking for an array of strings as in:
>
>    @recipients = ["removed_email_address@domain.invalid", 
"removed_email_address@domain.invalid"]
>
> As an alternate solution, I believe you could pass the email array to
> send_email (as your first example had it) and iterate over the array
> there adding the address for each email to @recipients.

Ok.  As far as the way I have it right now, is there anything wrong with
doing it the way I have it?  Trying to develop good habits from the
start :-)
Steven S. (Guest)
on 2005-12-18 03:29
(Received via mailing list)
I think it's looking for an array of strings as in:

   @recipients = ["removed_email_address@domain.invalid", 
"removed_email_address@domain.invalid"]

As an alternate solution, I believe you could pass the email array to
send_email (as your first example had it) and iterate over the array
there adding the address for each email to @recipients.
Steven S. (Guest)
on 2005-12-18 05:41
(Received via mailing list)
Not as far as I know.

How you implement it just depends on whether or not you want to send
one email to all the recipients (To: removed_email_address@domain.invalid, 
removed_email_address@domain.invalid) or a
separate email to each recipient (one to bob, and one to joe).
Vivek K. (Guest)
on 2005-12-30 15:25
(Received via mailing list)
Hi ,
  I am trying to get Action mailer work for me. and I have a problem
figuring out what is the 'mail' object thats passed to the deliver
method.
How do I create it?
the doc says
mail = MyMailer.create_some_email

but what is this supposed to return?
Thanks
Vivek
Steven S. (Guest)
on 2005-12-30 19:55
(Received via mailing list)
It is a TMail::Mail object.

http://railsmanual.org/module/TMail

If you have questions about other objects / classes, etc. you can
print out the class of an object as follows:

mail = MyMailer.create_some_email
logger.debug("mail class: #{mail.class}")
This topic is locked and can not be replied to.