Rookie with ActionMailer

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 [email protected]

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

[email protected] 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 = ‘[email protected]
@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

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.

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?

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).

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
}

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. 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 = ‘[email protected]
@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?

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’)

I think it’s looking for an array of strings as in:

@recipients = [“[email protected]”, “[email protected]”]

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. wrote:

I think it’s looking for an array of strings as in:

@recipients = [“[email protected]”, “[email protected]”]

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 :slight_smile:

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: [email protected], [email protected]) or a
separate email to each recipient (one to bob, and one to joe).

I think it’s looking for an array of strings as in:

@recipients = [“[email protected]”, “[email protected]”]

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.

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

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}”)