Prodipta Ghosh Prodipta Ghosh - 2 months ago 8
R Question

sending mail from R (mailR)

I am trying to send mail from R on a windows 7 (home) machine. I tried the following code

send.mail(from = "mymailid@gmail.com",
to = c("mymailid@gmail.com"),
subject = "Subject of the email",
body = "Body of the email",
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "myuserid", passwd = "my password", ssl = TRUE),
authenticate = TRUE,
send = TRUE)


I get the following error:
Error in ls(envir = envir, all.names = private) :
invalid 'envir' argument

after that I tried set up an hmail server (with a local domain name and user account, and smtp set up for smtp.gmail.com:25)

send.mail(from = "localuser@localdomain.local",
to = c("mymailid@gmail.com"),
subject = "Subject of the email",
body = "Body of the email",
smtp = list(host.name = "mail.hmailserver.com", port = 25),
authenticate = FALSE,
send = TRUE)


I still get the same error. Any help will be greatly appreciated. Thanks vm

Answer

If your gmail account is propertly setup (as mOnhawk suggested) then this form should work for the smtp list:

smtp = list(host.name = "smtp.gmail.com", port = 465,
                        ssl=TRUE, user.name = "mymailid@gmail.com",
                        passwd = "my password)