Class: InboxBeam::Client
- Inherits:
-
Object
- Object
- InboxBeam::Client
- Defined in:
- lib/inbox_beam/client.rb
Overview
Writes a message directly into your own mailbox using IMAP APPEND.
This is NOT email delivery. Nothing is sent over SMTP and no message leaves for another server — it is appended straight into the target mailbox. Use it to land your own app notifications in your own inbox without SPF/DKIM/DMARC.
Constant Summary collapse
- DEFAULT_PORT =
993- DEFAULT_MAILBOX =
"INBOX"
Instance Method Summary collapse
-
#append(mailbox, raw, unread: true) ⇒ InboxBeam::Result
Append an already-encoded RFC 5322 message (e.g. Mail::Message#encoded).
-
#beam(subject:, text: nil, html: nil, from: nil, to: nil, mailbox: nil, unread: nil, date: nil) ⇒ InboxBeam::Result
Append one message to the mailbox.
-
#initialize(host:, auth:, port: DEFAULT_PORT, ssl: true, mailbox: DEFAULT_MAILBOX, from: nil, to: nil, unread: true, subject_prefix: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(host:, auth:, port: DEFAULT_PORT, ssl: true, mailbox: DEFAULT_MAILBOX, from: nil, to: nil, unread: true, subject_prefix: nil) ⇒ Client
Returns a new instance of Client.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/inbox_beam/client.rb', line 28 def initialize(host:, auth:, port: DEFAULT_PORT, ssl: true, mailbox: DEFAULT_MAILBOX, from: nil, to: nil, unread: true, subject_prefix: nil) @host = host @auth = auth @port = port @ssl = ssl @mailbox = mailbox @from = from @to = to @unread = unread @subject_prefix = subject_prefix end |
Instance Method Details
#append(mailbox, raw, unread: true) ⇒ InboxBeam::Result
Append an already-encoded RFC 5322 message (e.g. Mail::Message#encoded).
58 59 60 61 62 63 |
# File 'lib/inbox_beam/client.rb', line 58 def append(mailbox, raw, unread: true) flags = unread ? [] : [:Seen] response = with_connection { |imap| imap.append(mailbox, raw, flags, nil) } uid_validity, uid = append_uid(response) Result.new(mailbox: mailbox, uid: uid, uid_validity: uid_validity) end |
#beam(subject:, text: nil, html: nil, from: nil, to: nil, mailbox: nil, unread: nil, date: nil) ⇒ InboxBeam::Result
Append one message to the mailbox.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/inbox_beam/client.rb', line 44 def beam(subject:, text: nil, html: nil, from: nil, to: nil, mailbox: nil, unread: nil, date: nil) to ||= @to || @auth[:user] from ||= @from || to mailbox ||= @mailbox unread = @unread if unread.nil? subject = "#{@subject_prefix} #{subject}" if @subject_prefix raw = Message.build(from: from, to: to, subject: subject, text: text, html: html, date: date) append(mailbox, raw, unread: unread) end |