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.

library(mailR)
  send.mail(from= ("bbb@gmail.com"),
            to = ("<aaa@gmail.com>"),
            subject="Mail from R Trial",
            body="HelloWorld!",
            smtp=list(host.name="smtp.gmail.com",port=465,user.name="datatalks247",passwd=pass,ssl=TRUE),
            authenticate =TRUE,
            send =TRUE,
            html=TRUE,
            debug=TRUE)

ERROR MSG :
Error in send.mail(from = ("bbb@gmail.com"), to = ("aaa@gmail.com"), :
could not find function "send.mail"

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

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 console.cloud.google.com/apis/credentials ... 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?

use_secret_file("test3.json")

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("receipent1@gmail.com","receipent2@gmail.com"),
  From = "sender@gmail.com",
  subject="Hello World!",
  body="Can you hear me from R?")
send_message(test_email)  

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.