I am working on Action mailer, email is sent successfully but incoming email not receiving.Below the code which i try
user_mailer.rb
**class UserMailer < ApplicationMailer**
** default from: “GMAIL_ACCOUNT”**
****
** def send_mail_agent(user)**
****
@user = user
****
** mail :to => user.email, :subject => “your ticket in process”**
****
** end**
****
** def receive(email)**
****
** page = Page.find_by(address: email.to.first)**
****
** page.emails.create(**
****
** subject: email.subject,**
****
** body: email.body**
****
** )**
****
** if email.has_attachments?**
****
** email.attachments.each do |attachment|**
****
** page.attachments.create({**
****
** file: attachment,**
****
** description: email.subject**
****
** })**
****
** end**
****
** end**
****
** end**
****
**end**
**development.rb **
****ActionMailer::Base.smtp_settings = {
address: 'smtp.gmail.com', # default: localhost
port: '25', # default: 25
user_name: 'GAMIL_ACCOUNT',
password: 'GMAIL_PASSWORD',
authentication: :plain # :plain, :login or :cram_md5
}
I tried to run the command **rails runner 'UserMailer.receive(STDIN.read)'**
But nothing happened even the email is incoming .It does not call the **receive** method
Where should i call the **receive** method ??? How determine the incoming email ???
Receiving email is rather more involved than sending it.
To use rails runner as you've tried this command needs to be run on your email server, by the email serving program itself (i.e. sendmail itself). There are variants on this but they all boil down to running your own mail server, which you may not want to do
Alternatively there are services like sendgrid, cloudmailin, Amazon ses. You set you ready dns records to that email to your domain (or a subdomain) is handled by this service provider and they'll make a regular http(s) call to your app whenever an email is received.
Fred
Now I am using the gem **mailman **and it work properly on receiving the email,
**mailman_server ** require “rubygems”
require "bundler/setup"
require "mailman"
Mailman.config.logger = Logger.new("log/mailman.log")
Mailman.config.pop3 = {
server: 'pop.gmail.com', port: 995, ssl: true,
username: "alchemative1@gmail.com",
password: "lahore786"
}
Mailman::Application.run do
default do
begin
Ticket.receive_mail(message)
rescue Exception => e
Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
Mailman.logger.error [e, *e.backtrace].join("\n")
end
end
end
And run the command **script/mailman_server** and its work properly.
So it good approach which i mention above ??? or i try to use service provide "sendgrid, cloudmailin, Amazon ses"???
And run the command script/mailman_server and its work properly.
So it good approach which i mention above ??? or i try to use service provide "sendgrid, cloudmailin, Amazon ses"???
If you want to use your gmail address then you have to use something like the gem you found - the services I mention require you to have control over the whole domain.
You should change your password though, since you've just posted it on the internet.
Fred