forked from mikel/mail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose the SMTP envelope From and To addresses and allow them to be o…
…verridden. Envelope From address defaults to return_path || sender || from_addrs.first. Envelope To address defaults to destinations (to + cc + bcc). Updates all delivery methods to rely on the SMTP envelope. References mikel#421 and rails/rails#5985
- Loading branch information
Showing
12 changed files
with
252 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
module Mail | ||
module CheckDeliveryParams | ||
def check_delivery_params(mail) | ||
envelope_from = mail.return_path || mail.sender || mail.from_addrs.first | ||
if envelope_from.blank? | ||
raise ArgumentError.new('A sender (Return-Path, Sender or From) required to send a message') | ||
if mail.smtp_envelope_from.blank? | ||
raise ArgumentError.new('An SMTP From address is required to send a message. Set the message smtp_envelope_from, return_path, sender, or from address.') | ||
end | ||
|
||
destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations | ||
if destinations.blank? | ||
raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message') | ||
if mail.smtp_envelope_to.blank? | ||
raise ArgumentError.new('An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.') | ||
end | ||
|
||
message ||= mail.encoded if mail.respond_to?(:encoded) | ||
message = mail.encoded if mail.respond_to?(:encoded) | ||
if message.blank? | ||
raise ArgumentError.new('A encoded content is required to send a message') | ||
raise ArgumentError.new('An encoded message is required to send an email') | ||
end | ||
|
||
[envelope_from, destinations, message] | ||
[mail.smtp_envelope_from, mail.smtp_envelope_to, message] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.