Sending Automated Emails from R

Hi there, I am trying to send email from R to a gmail account.
Following is the code I am using and R returns an Error msg shown below.

  send.mail(from= (""),
            to = ("<>"),
            subject="Mail from R Trial",
            authenticate =TRUE,
            send =TRUE,

Error in send.mail(from = (""), to = (""), :
could not find function "send.mail"

Any idea to solve this? or any other alternative solution you all could suggest?
Thanks in advance.

Do you have the mailR package installed? Do you get an error when running library(mailR)? It seems like R can't find the send.mail() function which suggests you haven't loaded the package namespace.

I use the {gmailr} package for sending automated emails from a Gmail account, and it works very well for me. So I can suggest that package from personal experience.

1 Like

@mattwarkentin Thanks for the reply!.

I am trying to explore your recommended {gmailr} package. I am facing some issues.

I visited ... created a project and downloaded ID in the .json format.

However, when I ran following code, I did get this error. Any idea why this happens?


Warning message for above code:
"Use gm_auth_configure() to configure your own OAuth app. That will
dictate the app used when gm_auth() is called implicitly or explicitly to
obtain an OAuth2 token."

gm_auth_configure(path = "json stored at working directory and the path given here/id name.json")

No message on the console window and did not direct to the browser either.

test_email <- gm_mime(
  To= c("",""),
  From = "",
  subject="Hello World!",
  body="Can you hear me from R?")

The ERROR message as follows:
Error: Can't get Google credentials.
Are you running gmailr in a non-interactive session? Consider:

  • Call gm_auth() directly with all necessary specifics.

Any idea with this errors.

Thank you in advance.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.