Initially, I thought this was because I was trying to attach multiple files (3), but during testing I've found it doesn't even work for one.
I write a dataframe to disk, then pass the path to attach.files (this approach is the one which has worked before). Consider the following:
#df passed as argument, totally normal dataframefname<-paste0('attach/attach_df_',gsub(' ','-',gsub(':','-',Sys.time())),'.csv')write.csv(df,fname)read.csv(fname) #works fine, prints the small dataframe I want to attachsource('cryptRead.R') #contains my email/username and passwordsend.mail(from=logins$user,to='primary_email@protonmail.com',cc=logins$user,subject=paste0('Test Email (',gsub(' ','-',gsub(':','-',Sys.time())),')'),body=strr, #strr passed as argumentsmtp=list(host.name='smtp.gmail.com',port=465,user.name=logins$user,passwd=logins$pwd, ssl=TRUE,attach.files=c(fname)),authenticate=TRUE,send=TRUE,debug=TRUE) # DOESNT WORK
send.mail(from=logins$user,to='primary_email@protonmail.com',cc=logins$user,subject=paste0('Test Email (',gsub(' ','-',gsub(':','-',Sys.time())),')'),body=strr, #strr passed as argumentsmtp=list(host.name='smtp.gmail.com',port=465,user.name=logins$user,passwd=logins$pwd, ssl=TRUE,attach.files=fname),authenticate=TRUE,send=TRUE,debug=TRUE) # ALSO DOESNT WORK
Not exactly sure what a 'character vector' is, but one of these should work; the second approach fname has worked for me previously and consistently in another script.
Fname is a valid path, as can be verified by calling read.csv()
Here's an example fname:
[1] "attach/attach_df_2018-01-12-10-28-20.csv"
In case it's not obvious, by 'DOESNT WORK', I mean that only the attachment fails. The other parts of the email (recipients, subject, body) are sent perfectly.
My bad!! I was putting attach.files in smtp()! Perhaps a warning for extraneous arguments to smtp would be helpful (for knuckleheads like me). There are also no problems with sending my 3 attachments
Initially, I thought this was because I was trying to attach multiple files (3), but during testing I've found it doesn't even work for one.
I write a dataframe to disk, then pass the path to
attach.files
(this approach is the one which has worked before). Consider the following:#df passed as argument, totally normal dataframe
fname<-paste0('attach/attach_df_',gsub(' ','-',gsub(':','-',Sys.time())),'.csv')
write.csv(df,fname)
read.csv(fname) #works fine, prints the small dataframe I want to attach
source('cryptRead.R') #contains my email/username and password
send.mail(from=logins$user,
to='primary_email@protonmail.com',
cc=logins$user,
subject=paste0('Test Email (',
gsub(' ','-',gsub(':','-',Sys.time())),')'),body=strr, #strr passed as argument
smtp=list(host.name='smtp.gmail.com',port=465,user.name=logins$user,
passwd=logins$pwd, ssl=TRUE,attach.files=c(fname)),
authenticate=TRUE,send=TRUE,debug=TRUE) # DOESNT WORK
send.mail(from=logins$user,
to='primary_email@protonmail.com',
cc=logins$user,
subject=paste0('Test Email (',
gsub(' ','-',gsub(':','-',Sys.time())),')'),body=strr, #strr passed as argument
smtp=list(host.name='smtp.gmail.com',port=465,user.name=logins$user,
passwd=logins$pwd, ssl=TRUE,attach.files=fname),
authenticate=TRUE,send=TRUE,debug=TRUE) # ALSO DOESNT WORK
Not exactly sure what a 'character vector' is, but one of these should work; the second approach
fname
has worked for me previously and consistently in another script.Fname is a valid path, as can be verified by calling
read.csv()
Here's an example fname:[1] "attach/attach_df_2018-01-12-10-28-20.csv"
In case it's not obvious, by 'DOESNT WORK', I mean that only the attachment fails. The other parts of the email (recipients, subject, body) are sent perfectly.