Module: MailMCP::SmtpClient

Defined in:
lib/mail_mcp/smtp_client.rb

Defined Under Namespace

Classes: ConnectionError

Constant Summary collapse

OPEN_TIMEOUT =
10
READ_TIMEOUT =
30

Class Method Summary collapse

Class Method Details

.send(config, mail) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mail_mcp/smtp_client.rb', line 11

def self.send(config, mail)
  smtp_open(config) do |s|
    recipients = mail.destinations
    MailMCP.logger.info do
      "SMTP send to=#{recipients.join(",")} from=#{mail.from&.first} subject=#{mail.subject.inspect}"
    end
    s.send_message(encoded_for_wire(mail), mail.from.first, recipients)
  end
rescue Net::SMTPError, SocketError => e
  MailMCP.logger.error { "SMTP send failed: #{e.class}: #{e.message}" }
  raise ConnectionError, "SMTP send failed: #{e.message}"
end

.validate!(config) ⇒ Object



7
8
9
# File 'lib/mail_mcp/smtp_client.rb', line 7

def self.validate!(config)
  smtp_open(config) { nil }
end