Problem Summary
I'm having problems with the Ruby mailfactory
gem (or Net::SMTP
) when I try to include addresses into the CC field. I'm not sure which of the two I might be using incorrectly.
Both test/production systems have the same version for mailfactory
, but different versions for the Ruby installation. I'm using mailfactory (1.4.0)
. The test system has ruby 2.1.2p95 (2014-05-08) [x86_64-linux-gnu]
and the production system has ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
.
Current Code
This is the code I have in my email-sending function:
mail = MailFactory.new
to_addr = '[email protected]'
cc_addr = ['[email protected]', '[email protected]']
#
# ...ommitted for brevity...
#
mail.to = to_addr
mail.cc = cc_addr.join ';'
mail.from = '[email protected]'
mail.subject = "Subject here"
mail.text = "Some text here"
mail.html = "Some HTML text here"
Net::SMTP.start('[email protected]', 25) do |smtp|
smtp.send_message(mail.to_s, mail.from.to_s, to_addr)
end
The code above works, but only partially. Those in the CC list seem to receive the emails when I run my tests (and only sometimes), but when the code runs in production, no one in the CC list seems to receive the copies. (I happen to be in the CC list and I never get any of them.)
I've tried a few different things, including joining to_addr
and cc_addr
into a single string, as follows:
cc_addr << to_addr
Net::SMTP.start('[email protected]', 25) do |smtp|
smtp.send_message(mail.to_s, mail.from.to_s, cc_addr.join(';'))
end
This did not work, either.
I also tried using mailfactory
's add_header
method:
mail.add_header('To', to_addr)
mail.add_header('Cc', cc_addr.join(';'))
mail.add_header('From', "[email protected]")
# etc...
This did not work, either. Addresses in the CC list don't get the messages (not even in the test environment, which used to work). In fact, even if the CC contains a single string, it still doesn't work.
Other Observations
Here're a few more things I've directly observed:
When I
puts mail.to_s
to the terminal, the mail headers appear to be OK (i.e. I see the addresses, including CCs -see samples below);When a user replies to one of the emails received, all the addresses are clearly listed in the CC fields, even though no one seems to have received them (at least I know I didn't);
The same SMTP server (IT-managed) is used by other non-Ruby programs to send emails, including CCs, and there're no issues;
The program runs normally (i.e. no warnings or error messages show up);
The email addresses are valid, even though I once got a mail delivery notification failure for one such address (have not seen that again, seemed to be a one-time issue on the IT side)
Trying to
join
several addresses into theTo:
field does not work. (The source code seems to limit theto
field to a single address.)
I had already checked other references/examples, but they're very simplistic and focus on a single To:
, From:
, etc. Since that already seems to work for me, they're of no use.
Header Sample 1
Here're the actual email headers, as produced by puts mail.to_s
, with addresses and domain edited for obvious reasons.
The headers below were produced with the use of
mail.add_header('To:', '[email protected]')
mail.add_header('From:', '[email protected]')
mail.add_header('Cc:', '[email protected]')
...and so on. The output was:
To: [email protected]
From: [email protected]
Cc: [email protected]
Cc: [email protected]
Reply-to: [email protected]
Subject: The subject
Message-ID: <[email protected]>
Date: Thu, 18 Feb 2016 08:07:22 -0800
MIME-Version: 1.0
Content-Type: multipart/alternative;boundary="----=_NextPart_APX_H3L1_qoWN58XIkVGr5SL_"
Header Sample 2
The headers below were produced with the use of
mail.to = '[email protected]'
mail.cc = cc_addr.join ';'
...and so on. They produced:
to: [email protected]
cc: [email protected];[email protected]
from: [email protected]
subject: =?utf-8?Q?The_subject?=
Message-ID: <[email protected]>
Date: Thu, 18 Feb 2016 08:25:36 -0800
MIME-Version: 1.0
Content-Type: multipart/alternative;boundary="----=_NextPart_hTUHy..uLF3qVgnLqYEaQKd21"
The different casing in the headers seems to make no difference. In both cases, only the address listed in the To:
field receives the mail. Those in the Cc:
don't.
Questions
Any ideas on what I might be missing here?
Should I even be using
mailfactory
? (Recently noticed some repos w/ their last commit 8yrs+ ago...)If this is deprecated/obsoleted, what is its replacement and where can I find it + docs/examples? (I've not found meaningful docs for
mailfactory
...)Am I using
Net::SMTP
incorrectly or just missing something there?
I'm been browsing a few other libs, and I saw mail
and Pony
suggested in a different SO post, though I'm not sure if I'm just going to run into the same problem...
Help appreciated.
Other References
I already went through other SO questions, including, but not limited to those below. I tried some of their suggestions, but they didn't seem to work for me.