开发者

With sendmailR, how can I specify a recipient/sender name along with the address?

开发者 https://www.devze.com 2023-04-07 10:50 出处:网络
I am using sendmailR to send emails but I cannot get it to work with a name associated with the email addresses, like \"Sender name\" <sender@domain.com>

I am using sendmailR to send emails but I cannot get it to work with a name associated with the email addresses, like "Sender name" <sender@domain.com>

With Postfix as the SMTP server, it throws SMTP Error: 5.5.4 Unsupported option: <sender@domain.com>.

Which syntax or parameter should be used? Your advice is welcome!

Following the example:

开发者_StackOverflowfrom <- "\"Sender name\" <sender@domain.com>"
to <- "<olafm@datensplitter.net>"
subject <- "Hello from R"
body <- list("It works!", mime_part(iris))
sendmail(from, to, subject, body,
control=list(smtpServer="ASPMX.L.GOOGLE.COM"))


From one side, one e-mail address can't contain any whitespace non-quoted, it should have a form "\"Sender name Or Any name with any whitespace you want\"<sender@domain.com>".

And from the other side, e-mail addresses used in to and from fields format depends on the server.

For example, when using Google's ASPMX.L.GOOGLE.COM SMTP I was only able to write the addresses in the following form:

from <- "<sender@domain.com>"

Options like

  • "\"Sender name\"<sender@domain.com>";
  • "\"Sender name\" <sender@domain.com>";
  • "Sender name<sender@domain.com>";
  • or "Sender name <sender@domain.com>"

were not accepted and generated either

SMTP Error: 5.5.2 Syntax error.

(for the 1st option) or

SMTP Error: 5.5.4 Unsupported option

(for options 2-4, I suppose, because of whitespace).

But when I tried custom SMTP server, I was able to use both from <- "<sender@domain.com>" and "\"Sender name\"<sender@domain.com>" - the second one gave exactly what I expected to get.


You must not include any space between the quoted name and the email address enclosed in <>. Here is the correct code:

from <- "\"Sender name\"<sender@domain.com>"
to <- "\"Recipient name\"<olafm@datensplitter.net>"
subject <- "Hello from R"
body <- list("It works!", mime_part(iris))
sendmail(from, to, subject, body,
control=list(smtpServer="ASPMX.L.GOOGLE.COM"))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号