I believe I setup mailboxer gem correctly. Messages work. In my User.rb model I have:
def mailboxer_email(object)
email
end
However no email gets sent to the receiving user when said user receives a message (I believe by default mailboxer should send this email).
How should I begin debugging this?
Currently, in my messages_controller.rb I have tried manually sending the email:
Mailboxer::MessageMailer.new_message_email("You have received a new message.", recipients)
But I'm not sure if it's working...
Related
Want to use Griddler for uploading attachments etc in my rails app but only want a certain email address to be forwarded to my rails app is this possible cant find and docs on this as an option
I don't believe there is from the SendGrid side of the workflow, but you can always in your Rails application look at the To tag in the email object and see if it matches the email you'd like.
class EmailProcessor
def initialize(email)
#email = email
end
def process
if #email.to == 'special#email.com'
# do something
else
# handle invalid email
end
end
end
I noticed that Mail gem doesn't get loaded outside ActionMailer context, but the gem is present in the proper gem group of Gemfile and then "loaded" upon Rails initialization.
To create a Mail object in a controller using Mail.new I need to put
require 'mail'
at the top of example_controller.rb, before
class ExampleController < ApplicationController
Could someone explain to me why?
Background:
I need to build an app whose functionality is primarily based on receiving emails of various types. I need to expose only one email address, where people will send all of these emails.
My mail server will pipe the raw email to a ruby script that sends the raw email as a POST request to my app.
Then, I need to identify which kind of email has arrived inferring that from its content (primarily attachments).
For example, let's have emails of types A, B and C. My email processing function will call one of three methods once it identifies the type of the email.
Where should I put the processing function?
You shouldn't be creating mail objects in your controllers. You should create a mailer and then call that mailer from your controller to send any emails you need to.
For example, say you have the following mailer in app/mailers/customer_mailer.rb:
class CustomerMailer < ActionMailer::Base
def send_reminder(user)
#user = user
mail to: user.email, subject: 'Reminder'
end
end
You can then call this from your controller as needed:
class ExampleController < ApplicationController
def some_action
#user = User.find(params[:id])
CustomerMailer.send_reminder(#user).deliver_now
end
end
This way your controller can focus on the implementations specific to controlling the request, and leave the mailer to worry about how to send email.
It's worth noting you also have access to a deliver_later method if you're using a background job runner.
Take a look at the documentation for more details: http://guides.rubyonrails.org/action_mailer_basics.html
Actually I am using devise for login and registration and its working fine, it send a confirmation email which is really good. But I need to send confirmation email in specific cases. I am passing user type in URL and on behalf of that I want to set mail. I have two type of users, one will be confirm their account their self reset of the users can not confirm their account only admin can approve their accounts. I have override the create method
def create
super
if params[:type]=='xyz
#user.skip_confirmation_notification!
end
end
but it sends mail in both cases. Please tell where am wrong.
So according to devise confirmable module you can skip to send confirmation and email by following code.
def confirm_your_type_user_without_confirmation_email
# check your condition here and process the following
self.skip_confirmation!
self.confirm!
# condition may end here
end
Now lets call it on create hook.
class User < ActiveRecord::Base
after_create :confirm_your_type_user_without_confirmation_email
....
end
for more reference you may check this:
Devise Confirmable module
The solution should be something similar as I mentioned here above. And its best practice to avoid controller to handle these responsibilities, because its not something your controller should take. :)
I hope my answer will give you some way to solve your problems! Thanks!
I'm trying to use ActionMailer for the first time.
My mailer looks like this:
class RequestMailer < ActionMailer::Base
default from: "fred#ameipro.com"
def request_email(worequest)
#worequest = worequest
mail(:to => "dave#ameipro.com", :subject => "New Service Request")
end
end
But, I get the following error:
Net::SMTPFatalError in WorequestsController#create
550 Cannot receive from specified address <fred#ameipro.com>: Unauthenticated senders not allowed
How do I correct?
Thanks!
This is an error from the mail server - it is refusing to deliver email from your address. Thats the part you need to diagnose. To help you, we'd need more information about the server you're trying to send through. To troubleshoot, I would try configuring a different client to send through your server, then try to send an email from fred#ameipro.com to dave#ameipro.com and see what happens.
We have an application built in rails 3.2.8. We are sending emails to customers. I want to block certain emails addressses. Basically mailer just ignore those particular email addresses.
For example: My company name is abc and I dont want to send emails to all my employees ie john#abc.com or rayn#abc.com ie *#abc.com
How can I do this?
PS: I am using sendgrid, they are not providing anything like this.
EDIT:
Placing this code in initializers directory:
class EmailAddressFilter
def self.delivering_email(message)
message.perform_deliveries = false
end
end
ActionMailer::Base.register_interceptor(EmailAddressFilter)
Should block all the emails. But still I can see emails in my development log.
PS: I have restarted my server.
In a file in config/initializers you can add something like this
class EmailAddressFilter
def self.delivering_email(message)
# permit or deny the message using its "to", "body" etc properties
# note message.to is an array (multiple emails)
message.perform_deliveries = Email.whitelisted?(message.to)
end
end
ActionMailer::Base.register_interceptor(EmailAddressFilter)