{emayili} Message Threads
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Being able to view related messages as threads is really useful. To make this possible, messages must use either the In-Reply-To or References header field to link to the Message-ID from another message.
This is now possible in {emayili}.
library(emayili)
options(envelope.details = TRUE)
options(envelope.invisible = FALSE)
packageVersion("emayili")
[1] '0.6.3'
Let’s configure an SMTP server.
smtp <- server(
host = Sys.getenv("SMTP_SERVER"),
port = Sys.getenv("SMTP_PORT"),
username = Sys.getenv("SMTP_USERNAME"),
password = Sys.getenv("SMTP_PASSWORD")
)
Now create and send a message to start the thread.
msg <- envelope(
from = Sys.getenv("SMTP_USERNAME"),
to = Sys.getenv("SMTP_USERNAME")
)
msg %>%
subject("Original message") %>%
smtp()
When the message is delivered you can find the value of the Message-ID field among the other headers.
Message-ID: <[email protected]> Date: Sun, 17 Oct 2021 22:25:33 -0700 (PDT) X-Google-Original-Date: Mon, 18 Oct 2021 05:25:32 GMT X-Mailer: {emayili}-0.6.5 MIME-Version: 1.0 Subject: Original message
This can then be used to send a response in the same thread.
msg %>%
inreplyto("<[email protected]>") %>%
subject("First reply") %>%
smtp(verbose)
Message-ID: <[email protected]>
Date: Sun, 17 Oct 2021 22:26:27 -0700 (PDT)
X-Google-Original-Date: Mon, 18 Oct 2021 05:25:32 GMT
X-Mailer: {emayili}-0.6.5
MIME-Version: 1.0
In-Reply-To: <[email protected]>
Subject: First reply
Notice that the In-Reply-To field contains the value of the Message-ID field from the original message. This message, in turn, has a Message-ID which can be used for subsequent responses. Note: The Message-ID from the response looks very similar to that from the original message, but if you look carefully you’ll see that it differs by a few characters.
Let’s send a response to this too.
msg %>%
inreplyto("<[email protected]>") %>%
subject("Comment on first reply") %>%
smtp()
You can also use the references() function to populate the References field, which has essentially the same effect as the In-Reply-To field. How about another reply to the original message?
msg %>%
references("<[email protected]>") %>%
subject("Second reply") %>%
smtp()
Message-ID: <[email protected]>
Date: Sun, 17 Oct 2021 22:26:45 -0700 (PDT)
X-Google-Original-Date: Mon, 18 Oct 2021 05:25:32 GMT
X-Mailer: {emayili}-0.6.5
MIME-Version: 1.0
References: <[email protected]>
Subject: Second reply
This is what the thread looks like in Thunderbird after sending a few more responses.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
