用gmail通过R用电子邮件发送附件 [英] Email an attachment in R with gmail

查看:108
本文介绍了用gmail通过R用电子邮件发送附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用gmail在R中发送带有附件的电子邮件.我发现sendmailR不适用于gmail,因为它需要身份验证(我无法使其与gmail一起使用,因此除非有人告诉我我错了,否则我认为这是正确的,在这种情况下,我将发布R输出和错误消息).我在此处(LINK)找到了一个代码段.正如该网站所建议的那样,该代码未设置为发送附件的格式,但是我已经知道它可以发送电子邮件.我想扩展此代码以发送附件(在电子邮件通讯中,此代码的作者无法扩展该代码以发送附件).

I am desiring to send an email in R with an attachment using gmail. I have found that sendmailR does not work with gmail because it requires authentication (I couldn't get it to work with gmail so I assume this to be true unless someone tells me I'm wrong , in which case I'll post the R output and error message for that). I found a code snippet found here (LINK). As the site suggests the code is not formatted to send attachments but I have got it to send an email. I'd like to extend this code to send attachments (in an email correspondence the author of this code was unable to extend the code to send attachments).

我想使用gmail发送带有R的电子邮件.我是Windows 7用户,使用R 2.14 beta版.

I want to send emails with R using gmail. I am a windows 7 user with the 2.14 beta version of R.

发送电子邮件但不发送附件的代码:

The code that sends emails but not attachments:

require(rJython) 
rJython <- rJython() 
rJython$exec( "import smtplib" ) 
rJython$exec("from email.MIMEText import MIMEText") 
rJython$exec("import email.utils") 

mail<-c( 
#Email settings 
"fromaddr = 'bigbird@gmail.com'", 
"toaddrs  = 'oscarthegrouch@gmail.com'", 
"msg = MIMEText('This is the body of the message.')", 
"msg['From'] = email.utils.formataddr(('sender name', fromaddr))", 
"msg['To'] = email.utils.formataddr(('recipient name', toaddrs))", 
"msg['Subject'] = 'Simple test message'", 

#SMTP server credentials 
"username = 'bigbird@gmail.com'", 
"password = 'pw'", 

#Set SMTP server and send email, e.g., google mail SMTP server 
"server = smtplib.SMTP('smtp.gmail.com:587')", 
"server.ehlo()", 
"server.starttls()", 
"server.ehlo()", 
"server.login(username,password)", 
"server.sendmail(fromaddr, toaddrs, msg.as_string())", 
"server.quit()") 

jython.exec(rJython,mail) 

请注意,此消息是交叉发布在talkstats.com上的.我在那里没有收到答复(只是成员告诉我他们希望他们能提供帮助).如果我收到可行的解决方案,我也将其发布在这里.

Note this message is cross posted at talkstats.com. I did not receive a reply there (just members telling me they wish they could help). If I receive a workable solution i will also post it there as well.

推荐答案

在这里找到了行之有效的响应:
http://r.789695.n4.nabble.com/Email- out-of-R-code-td3530671.html

A response that works and works well is found here:
http://r.789695.n4.nabble.com/Email-out-of-R-code-td3530671.html

感谢nutterb从rhelp列表中寻找答案.感谢所有尝试为我提供帮助的人,并对我对python的了解感到耐心.

Thank you to nutterb for an answer from the rhelp list. Thank you to all that tried to assist me and were patient with my ignorance of python.

这篇关于用gmail通过R用电子邮件发送附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆