class UserMailer < ApplicationMailerdefault 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
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 ???
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: "alchem...@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"???