2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2020-02-05 12:50:49 +00:00
|
|
|
class EmailHelper
|
2015-08-23 20:21:04 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2015-08-30 11:58:05 +00:00
|
|
|
get available driver
|
|
|
|
|
|
|
|
result = EmailHelper.available_driver
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
2015-08-31 23:12:51 +00:00
|
|
|
inbound: {
|
|
|
|
imap: 'IMAP',
|
|
|
|
pop3: 'POP3',
|
|
|
|
},
|
|
|
|
outbound: {
|
|
|
|
smtp: 'SMTP - configure your own outgoing SMTP settings',
|
|
|
|
sendmail: 'Local MTA (Sendmail/Postfix/Exim/...) - use server setup',
|
|
|
|
},
|
2015-08-30 11:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.available_driver
|
|
|
|
if Setting.get('system_online_service')
|
|
|
|
return {
|
2018-12-19 17:31:51 +00:00
|
|
|
inbound: {
|
2021-11-15 15:58:19 +00:00
|
|
|
imap: __('IMAP'),
|
|
|
|
pop3: __('POP3'),
|
2015-08-31 23:12:51 +00:00
|
|
|
},
|
|
|
|
outbound: {
|
2021-11-15 15:58:19 +00:00
|
|
|
smtp: __('SMTP - configure your own outgoing SMTP settings'),
|
2015-08-31 23:12:51 +00:00
|
|
|
},
|
2015-08-30 11:58:05 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
2018-12-19 17:31:51 +00:00
|
|
|
inbound: {
|
2021-11-15 15:58:19 +00:00
|
|
|
imap: __('IMAP'),
|
|
|
|
pop3: __('POP3'),
|
2015-08-31 23:12:51 +00:00
|
|
|
},
|
|
|
|
outbound: {
|
2021-11-15 15:58:19 +00:00
|
|
|
smtp: __('SMTP - configure your own outgoing SMTP settings'),
|
2021-12-17 09:55:02 +00:00
|
|
|
sendmail: __('Local MTA (Sendmail/Postfix/Exim/…) - use server setup'),
|
2015-08-31 23:12:51 +00:00
|
|
|
},
|
2015-08-30 11:58:05 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
get mail parts
|
|
|
|
|
|
|
|
user, domain = EmailHelper.parse_email('somebody@example.com')
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
[user, domain]
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.parse_email(email)
|
|
|
|
user = nil
|
|
|
|
domain = nil
|
2021-05-12 11:37:44 +00:00
|
|
|
if email =~ %r{^(.+?)@(.+?)$}
|
2015-08-23 20:21:04 +00:00
|
|
|
user = $1
|
|
|
|
domain = $2
|
|
|
|
end
|
|
|
|
[user, domain]
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get list of providers with inbound and outbound settings
|
|
|
|
|
|
|
|
map = EmailHelper.provider(email, password)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
google: {
|
|
|
|
domain: 'gmail.com|googlemail.com|gmail.de',
|
|
|
|
inbound: {
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
|
|
|
host: 'imap.gmail.com',
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
outbound: {
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: 'smtp.gmail.com',
|
|
|
|
port: 25,
|
|
|
|
start_tls: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.provider(email, password)
|
|
|
|
# check domain based attributes
|
2020-07-07 06:30:20 +00:00
|
|
|
{
|
2015-09-06 07:50:51 +00:00
|
|
|
google_imap: {
|
2018-12-19 17:31:51 +00:00
|
|
|
domain: 'gmail|googlemail|google',
|
|
|
|
inbound: {
|
2015-08-23 20:21:04 +00:00
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'imap.gmail.com',
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
outbound: {
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'smtp.gmail.com',
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 587,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: email,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
microsoft: {
|
|
|
|
domain: 'outlook.com|hotmail.com',
|
|
|
|
inbound: {
|
2015-08-23 20:21:04 +00:00
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'imap-mail.outlook.com',
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
outbound: {
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'smtp-mail.outlook.com',
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 587,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: email,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2015-09-06 07:50:51 +00:00
|
|
|
google_pop3: {
|
2018-12-19 17:31:51 +00:00
|
|
|
domain: 'gmail|googlemail|google',
|
|
|
|
inbound: {
|
2015-09-06 07:50:51 +00:00
|
|
|
adapter: 'pop3',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'pop.gmail.com',
|
|
|
|
port: 995,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-09-06 07:50:51 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
outbound: {
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'smtp.gmail.com',
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 587,
|
2015-09-06 07:50:51 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: email,
|
|
|
|
password: password,
|
2015-09-06 07:50:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
2020-07-07 06:30:20 +00:00
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get possible inbound settings based on mx
|
|
|
|
|
|
|
|
map = EmailHelper.provider_inbound_mx(user, email, password, mx_domains)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
|
|
|
host: mx_domains[0],
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
|
|
|
host: mx_domains[0],
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.provider_inbound_mx(user, email, password, mx_domains)
|
|
|
|
inbounds = []
|
2017-10-01 12:25:52 +00:00
|
|
|
mx_domains.each do |domain|
|
2015-08-23 20:21:04 +00:00
|
|
|
inbound = [
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: domain,
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: domain,
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
2020-09-30 09:07:01 +00:00
|
|
|
inbounds.concat(inbound)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-08-23 20:21:04 +00:00
|
|
|
inbounds
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get possible inbound settings based on guess
|
|
|
|
|
|
|
|
map = EmailHelper.provider_inbound_guess(user, email, password, domain)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.provider_inbound_guess(user, email, password, domain)
|
2020-07-07 06:30:20 +00:00
|
|
|
[
|
2015-08-23 20:21:04 +00:00
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "imap.#{domain}",
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "imap.#{domain}",
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'pop3',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 995,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'pop3',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 995,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'pop3',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "pop.#{domain}",
|
|
|
|
port: 995,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'pop3',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "pop.#{domain}",
|
|
|
|
port: 995,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'pop3',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "pop3.#{domain}",
|
|
|
|
port: 995,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'pop3',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "pop3.#{domain}",
|
|
|
|
port: 995,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
2020-07-07 06:30:20 +00:00
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get possible outbound settings based on mx
|
|
|
|
|
|
|
|
map = EmailHelper.provider_outbound_mx(user, email, password, mx_domains)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: domain,
|
|
|
|
port: 25,
|
|
|
|
start_tls: true,
|
|
|
|
user: user,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: domain,
|
|
|
|
port: 25,
|
|
|
|
start_tls: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.provider_outbound_mx(user, email, password, mx_domains)
|
2015-08-23 20:26:03 +00:00
|
|
|
outbounds = []
|
2017-10-01 12:25:52 +00:00
|
|
|
mx_domains.each do |domain|
|
2015-08-23 20:26:03 +00:00
|
|
|
outbound = [
|
2015-08-23 20:21:04 +00:00
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: domain,
|
|
|
|
port: 465,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: user,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: domain,
|
|
|
|
port: 465,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: email,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
2020-02-05 12:50:49 +00:00
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: domain,
|
|
|
|
port: 587,
|
|
|
|
user: user,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: domain,
|
|
|
|
port: 587,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
2022-05-09 06:23:30 +00:00
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: domain,
|
|
|
|
port: 25,
|
|
|
|
start_tls: true,
|
|
|
|
user: user,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: domain,
|
|
|
|
port: 25,
|
|
|
|
start_tls: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
2015-08-23 20:21:04 +00:00
|
|
|
]
|
2020-09-30 09:07:01 +00:00
|
|
|
outbounds.concat(outbound)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-08-23 20:26:03 +00:00
|
|
|
outbounds
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get possible outbound settings based on guess
|
|
|
|
|
|
|
|
map = EmailHelper.provider_outbound_guess(user, email, password, domain)
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: user,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.provider_outbound_guess(user, email, password, domain)
|
2020-07-07 06:30:20 +00:00
|
|
|
[
|
2015-08-23 20:21:04 +00:00
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "mail.#{domain}",
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 465,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: user,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "mail.#{domain}",
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 465,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: email,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2022-05-09 06:23:30 +00:00
|
|
|
host: "smtp.#{domain}",
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 465,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: user,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2022-05-09 06:23:30 +00:00
|
|
|
host: "smtp.#{domain}",
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 465,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: email,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
2022-05-09 06:23:30 +00:00
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 587,
|
|
|
|
start_tls: true,
|
|
|
|
user: user,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 587,
|
|
|
|
start_tls: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
2015-08-23 20:21:04 +00:00
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "smtp.#{domain}",
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 587,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: user,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "smtp.#{domain}",
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 587,
|
|
|
|
start_tls: true,
|
|
|
|
user: email,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: "mail.#{domain}",
|
|
|
|
port: 25,
|
|
|
|
start_tls: true,
|
|
|
|
user: user,
|
|
|
|
password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
|
|
|
host: "mail.#{domain}",
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 25,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: email,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "smtp.#{domain}",
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 25,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: user,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: "smtp.#{domain}",
|
2022-05-09 06:23:30 +00:00
|
|
|
port: 25,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: email,
|
|
|
|
password: password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
2020-07-07 06:30:20 +00:00
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get dns mx records of domain
|
|
|
|
|
|
|
|
mx_records = EmailHelper.mx_records('example.com')
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
['mx1.example.com', 'mx2.example.com']
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.mx_records(domain)
|
|
|
|
mail_exchangers = mxers(domain)
|
|
|
|
if mail_exchangers && mail_exchangers[0]
|
|
|
|
Rails.logger.info "MX for #{domain}: #{mail_exchangers} - #{mail_exchangers[0][0]}"
|
|
|
|
end
|
|
|
|
mx_records = []
|
|
|
|
if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
|
|
|
|
mx_records.push mail_exchangers[0][0]
|
|
|
|
end
|
|
|
|
mx_records
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.mxers(domain)
|
|
|
|
begin
|
|
|
|
mxs = Resolv::DNS.open do |dns|
|
|
|
|
ress = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
|
2017-10-01 12:25:52 +00:00
|
|
|
ress.map do |r|
|
2015-08-23 20:21:04 +00:00
|
|
|
[r.exchange.to_s, IPSocket.getaddress(r.exchange.to_s), r.preference]
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
|
|
|
rescue => e
|
2017-04-19 10:09:54 +00:00
|
|
|
Rails.logger.error e
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
|
|
|
mxs
|
|
|
|
end
|
|
|
|
|
2015-08-23 20:26:03 +00:00
|
|
|
end
|