Search code examples
remailsmtp

How to reply emails using emayili in R? How to get the message ID when sending an email with emayili?


I am sending emails with emayili, a great package BTW.

I want to send replies to my previous emails. For example, I send an email. Later, I want to reply to that specific email.

I know that the package has already provided two functions (which I don't really know the difference between them): inreplyto and references. These functions require a message ID (msgid) as their argument to identify the message that they are replying to.

So my question is how to get that message ID? Does emayili return such an ID when sending an email?


My sample code is:


message_content <- envelope(
  to      = "Reciever@gmail.com" %>% address(display = "MR. Reciever"),
  from    = "Sender@gmail.com" %>% address(display = "MR. Sender"),
  
  subject = "email_subject",
  importance = "high", 
  priority = "urgent"
) %>% 
  return_path("Sender@gmail.com" %>% address(display = "MR. Sender"))
  

message_content <- message_content %>% 
  text("Hello!")

smtp <- gmail(
  username = "Sender@gmail.com",
  password = "**********"
)


smtp(message_content, verbose = F)



Solution

  • Andrew (datawookie) has skillfully resolved the issue. You can find our discussion on GitHub issues and refer to his insightful blog post.

    The solution involves three key components:

    1. Specifying a return_path: Ensuring proper routing for email replies.
    2. Creating a unique Message-ID: Andrew swiftly added this feature to {emayili}. Now you can generate random ID sequences for future reference—likely how email clients recognize related messages.
    3. Using IDs in emails: Specify the ID in the initial email and subsequent replies (in In-Reply-To and References).

    Don't miss Andrew's informative blog post!