Is cc possible for recipients using sendmail in R?

I want to send one letter to several recipients from R. I can achieve this using the sendmail function, but when the recipients receive an email, they only see their email address in the to field. It appears that sendmail performs internal cycles and sends customized emails to each recipient, which is not a true carbon copy . It is important that each recipient sees all recipients destined for their particular email (a business requirement, as they must respond to all recipients of this email). How can I achieve this using R?

my code

 require(sendmailR) to <- c(" vasudeva.naik@abc.com ") header <- list(cc=c(" alok.jadhav@abc.com ")) x <- sendmail(" toto@abc.com ", to, "test", "testing", header=header,control=list(smtpServer=server,verbose=TRUE)) << 220 equity.xyz.com ESMTP Sendmail 8.11.7p1+Sun/8.11.7; Thu, 11 Jul 2013 21:31:43 -0400 (EDT) >> HELO HKD03836654 << 250 equity.xyz.com Hello HKD03836654.gbl.ad.net [169.34.175.142], pleased to meet you >> MAIL FROM: toto@abc.com << 250 2.1.0 toto@abc.com... Sender ok >> RCPT TO: vasudeva.naik@abc.com << 250 2.1.5 vasudeva.naik@abc.com... Recipient ok >> DATA << 354 Enter mail, end with "." on a line by itself >> <message data> << 250 2.0.0 r6C1Vh101169 Message accepted for delivery >> QUIT << 221 2.0.0 equity.csfb.com closing connection 

Exits the debugging option. header information is not in the debug output.

 > sendmail(" toto@abc.com ", to, "test", "testing", header=header,control=list(smtpServer=server,transport="debug")) From: toto@abc.com To: vasudeva.naik@abc.com Subject: test Date: Mon, 15 Jul 2013 02:15:29 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1a556aa6576e231876dabb67e5a4f58730d3a228654e14705503b6985a6a6707" This is a message with multiple parts in MIME format. --1a556aa6576e231876dabb67e5a4f58730d3a228654e14705503b6985a6a6707 Content-Type: text/plain; format=flowed testing --1a556aa6576e231876dabb67e5a4f58730d3a228654e14705503b6985a6a6707-- 

Thanks.

+4
source share
5 answers

The problem is caused by using the header parameter instead of headers . However, this is not such a silly typo as one might think. As we know, we can shorten parameter names when calling functions:

 myfun <- function(xx = 1) print(xx) myfun(x = 2) # [1] 2 

It is also possible if ... :

 myfun <- function(xx = 1, ...) print(xx) myfun(x = 2) [1] 2 

But in this case, we have a different and unusual order of parameters:

 sendmail(from, to, subject, msg, ..., headers = list(), control = list()) 

which is not surprisingly causing such problems:

 myfun <- function(..., yy = 1) print(yy) myfun(y = 2) [1] 1 
+3
source

You need to combine all the real recipients and send an email for each of them separately. CC is merely informational as such; leave this and you get BCC So, for example:

 to <- c(" vasudeva.naik@abc.com ") # addresses for the "To" header cc <- c(" alok.jadhav@abc.com ") # addresses for the "CC" header bcc <- c("...") # more addresses, but these won't be visible anywhere recipients <- c(to, cc, bcc) # need to send the email to everyone (FIXME: drop duplicates) header <- list(cc=cc) # let everyone know who else gets the mail x <- sendmail(" toto@abc.com ", recipients, "test", "testing", header=header, control=list(smtpServer=server,verbose=TRUE)) 

If you need all the addresses in the To header, you can use header <- list(to=to) instead.

Please note that the above is not verified. It should work theoretically, but sendmailR may have other plans for handling some arguments.


Expand previous comment. There are two parts to sending email, SMTP is the protocol for delivering the message to the recipients and the content of the message itself.

SMTP, which handles delivery, looks something like this:

 MAIL FROM: toto@abc.com RCPT TO: vasudeva.naik@abc.com DATA <message content here, see below> . 

Note that FROM and To here correspond to the arguments to the sendmail() function. This determines who receives the mail.

Now the message content (well, only the headers) looks something like this:

 From: no-reply@example.com To: everyone@example.com CC: everyone-else@example.com 

And yes, FROM and To completely different from the previous ones. This is what the recipients receive and see, but it has nothing to do with whoever actually receives the email. Therefore, spam in your inbox appears as something you sent to someone else, even if you are the actual recipient.

+3
source

Try:

 > for (to in recipients) { + sendmail(from, to, subject, msg, control... 
+2
source

Several features (untested):

  • Put the recipient list as the first line in your message body. Rather clumsy, but it works. I really saw this with the Bcc: field (which defeats the Bcc: point, but it doesn't matter).

  • Instead of a vector of mail recipients, your to argument should contain a single line containing all recipients separated by commas.

+2
source

I encountered this problem earlier, I would like to know a more direct solution, but the way I decided was to create a mailing list and send one mail to the mailing list. Thus, everyone sees and can answer everyone on the list. Hope this solves your problem.

+1
source

Source: https://habr.com/ru/post/1490413/


All Articles