blastula icon indicating copy to clipboard operation
blastula copied to clipboard

Where to set password argument?

Open MislavSag opened this issue 4 years ago • 4 comments

I don't understand how can I send an email with the password? I don't want to enter it manually. Functions creds and create_smtp_creds_file doesn't have password argument.

I would like to schedule my script on windows, so mannualy enetering the password is not the solution.

MislavSag avatar Jun 29 '20 07:06 MislavSag

You can set an environment variable with Sys.setenv("SMTP_PASSWORD"="1234") and use creds_envvar function.

felipeangelimvieira avatar Jun 30 '20 19:06 felipeangelimvieira

I add this line on the beggining of the script, but it still asks me for password when I want to send e-mail.

MislavSag avatar Jul 06 '20 06:07 MislavSag

@felipeangelimvieira , it still ask me for password, even if I add Sys.setenv("SMTP_PASSWORD"="xxx") to the script

MislavSag avatar Jul 13 '20 11:07 MislavSag

@MislavSag a better way to set an environment variable with R is by putting it in your .Renviron file. It's really easy to open with usethis::edit_r_environ(). Once you're in the file, add the line SMTP_PASSWORD={password}.

The creds_envvar() function needs to be used at the credentials argument of smtp_send(). Like this (if you are using Gmail):

prepare_test_message() %>%
  smtp_send(
    from = "[email protected]",
    to = "[email protected]",
    subject = "The Subject",
    credentials = creds_envvar(
      user = "username",
      pass_envvar = "SMTP_PASSWORD",
      provider = "gmail"
    )
  )

Hope this helps.

rich-iannone avatar Aug 18 '20 16:08 rich-iannone