- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我强烈怀疑最受好评的答案将是“这是工作的错误工具”。我承认 R 可能不是特别适合发送和接收电子邮件,但它是我最了解的脚本语言。我希望找到一种在 R 中发送和接收短电子邮件的方法。有人知道在 Windows 平台上执行此操作的既定方法吗?我也许可以结合使用 BLAT 和 GetMail,但首选 native R 解决方案。
编辑:可接受的解决方案应该能够与需要 SSL 的服务器连接。
编辑 2:我提供了 80% 的答案。遗憾的是,没有演示 R native 方式。相反,我使用了可能无法跨平台兼容的系统调用和命令行程序的邪恶组合。 R native 调用需要深入研究 POP3 服务器喜欢与连接的客户端交谈的方式,以及我目前没有的对 SSL 的理解。其他答案仍然受到鼓励。
##Note: Other programs are wrapped in R functions and system calls.
#They each have their own licenses which may or may not allow the use suggested here
#Programs used here:
#STunnel: http://www.stunnel.org/; Provides an SSL tunnel but requires OpenSSL
#OpenSSL: http://www.openssl.org/; OpenSSL to actually provide SSL
# Note that these .dlls should be placed with the stunnel exe.
# Also note that libssl32.dll may need to be renamed from ssleay32.dll
#Microsoft Visual C++ 2008 Redistributable (may be required for the SSL .dlls to work correctly)
#Blat: http://www.blat.net; a public domain SMTP sending program
#Getmail is free for non-commercial use. If you use it in a business environment, then a fee of $50 USD is payable to Tim Charron.
#Stunnel is a TSR, so it will need to be killed from the task manager if there is an issue. If you are willing to install it as a service you may be able to tweak my code to start and stop the service.
#My current code does not create .conf file for stunnel the way a full version ought. Check http://spampal.sanesecurity.com/manual_eng/servers/stunnel/stunnel.htm#sconfig21 to create the appropriate configuration file.
#Set the config values as appropriate
##Config##
BLAT.loc <- "c:/Programming/R/Rmail/blat262/full/blat.exe"
GetMail.loc <- "C:/Programming/R/RMail/getmail133/getmail.exe"
stunnel.loc <- "C:/Programming/R/RMail/stunnel/stunnel-4.11.exe"
#The set mail function assigns the username and password to be used as well as the smtp and pop3 servers it starts stunnel (and assumes that the stunnel.conf file is present and set correctly).
setMail <- function(user,pw,SSL=FALSE,smtp="127.0.0.1:259",pop3="127.0.0.1:1109")
{
if (SSL==TRUE)
{
print("Starting stunnel; you will need to kill this from the task-manager")
system(stunnel.loc,wait=FALSE)
Sys.sleep(2) #Give it time to start
}
return(list(user=user,pw=pw,smtp=smtp,pop3=pop3,SSL=SSL))
}
#function to send mail, myMail is the resulting list from setMail
sendmail <- function(myMail, to, subject, msg,VERBOSE=FALSE)
{
writeLines(msg, "out.txt", sep = "\n", useBytes = FALSE)
targ <- paste(getwd(),"/out.txt",sep="")
call <- paste(BLAT.loc, ' "',targ,'" -subject "',subject,'" -to ',to," -u ",myMail$user," -pw ",myMail$pw, " -f ",myMail$user, " -debug -server ",myMail$smtp,sep="")
res <- system(call,intern=TRUE)
if (VERBOSE) {return(res)}
}
#function to get mail, myMail is the resulting list from setMail; it returns a list with one element that contains everything unparsed, another list provides the number of messages remaining on the server.
getmail <- function(myMail,VERBOSE=FALSE)
{
unlink("MSG1.txt") #drop previous get
#download next message
call <- paste(GetMail.loc," -u ",myMail$user," -pw ",myMail$pw," -s ",strsplit(myMail$pop3,":")[[1]][1],
" -port ",strsplit(myMail$pop3,":")[[1]][2]," -n 1",sep="")
res <- system(call,intern=TRUE)
if (VERBOSE) {print(res)}
nmsgtxt <- res[grep("messages on the server.",res)]
nstart <- regexpr("There are",nmsgtxt)
nend <- regexpr("messages on the server.",nmsgtxt)
nmess <- as.numeric(substr(nmsgtxt,10,nend-1))-1
x <- readLines("MSG1.txt",-1)
return(list(message=x,remaining=nmess))
}
最佳答案
从 Pop 服务器拉取消息
为了尝试实现@JorisMeys 利用其他语言的想法,我尝试使用 Python 和 rJython 包从 Gmail(通过 ssl)提取邮件。 Jython 是在 Java 虚拟机上实现的 Python,所以使用 rJython 对我来说有点像使用 R 调用 Java,然后伪装成 Python。
我发现 rJython 对于简单的事情很容易,但是由于我不精通 S4 对象和 (r)Java,我有时很难正确操作来自 rJython 的返回对象。但是,它有效。这是一个从 Gmail 帐户中提取单个邮件的基本结构:
library(rJython)
rJython <- rJython( modules = "poplib")
rJython$exec("import poplib")
rJython$exec("M = poplib.POP3_SSL('pop.gmail.com', 995)")
rJython$exec("M.user(\'yourGmailAddy@gmail.com\')")
rJython$exec("M.pass_(\'yourGmailPassword\')")
rJython$exec("numMessages = len(M.list()[1])")
numMessages <- rJython$get("numMessages")$getValue()
# grab message number one. Loop here if you
# want more messages
rJython$exec("msg = M.retr(1)[1]")
emailContent <- rJython$get("msg")
# turn the message into a list
contentList <- as.list(emailContent)
# so we have an R list... of Java objects
# To get a more native R list we have to
# yank the string from each Java item
messageToList <- function(contentList){
outList <- list()
for (i in 1:length(contentList)){
outList[i] <- contentList[[i]]$toString()
}
outList
}
messageAsList <- messageToList(contentList)
messageAsList
关于email - 如何使用 R 发送/接收(SMTP/POP3)电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4241812/
大家好,我是 php 和 html 新手,面临问题:SMTP 错误:无法连接到 SMTP 主机。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。但在本地 xampp 中工作正常,在服务器中出
我希望这个问题不是完全偏离主题。 我一直想知道 SMTP 电子邮件验证。有很多服务(例如 Kickbox.io、Email-Validator.net 等)似乎可以处理 SMTP 验证,而不会阻止其
我正在尝试使用 phpMailer 通过电子邮件向用户发送确认消息。我的代码是这样的: IsSMTP(); // set mailer to use SMTP $mail->Host = "ssl:/
我已经在我的本地机器(Windows 7)上安装了 bugzilla 并且它运行良好。但是当我尝试创建一个新帐户时,它说 There was an error sending mail from it
我有一个将发送大量输出的程序。我只是想知道最大电子邮件附件大小是多少?根据RFC 1870邮件服务器可以拒绝邮件,因为它们太大了,但是使用 SMTP/MIME 时有最大大小吗?我在这方面找不到任何东西
假设我有一个网站,其某些功能需要电子邮件验证(例如用户注册)。当然,我会使用正则表达式验证电子邮件,但曾几何时,我在其他人的代码中看到了 SMTP 验证。 SMTP 验证有哪些优点和缺点? 我可以假设
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 2年前关闭。 Improve thi
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我正在尝试使用 Vala 和 GLib + GIO 实现一个简单的 SMTP 服务器。 到目前为止,纯文本通信没有问题,但当涉及使用 STARTTLS 的 TLS 时,事情会变得更加困难。 这是我到目
我使用 go 的 net/smtp 发送电子邮件,它对某些电子邮件工作正常但对其他电子邮件无效。我收到 554 5.5.1 Error: no valid recipients 但我很确定我提供了正确
我需要帮助 这是我的代码: require 'PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->isSMTP(); $mail->Host =
我的 joomla 联系表 gmail SMTP 设置不起作用。请参阅下面提交联系表时显示的消息。应该是什么原因?extension=php_openssl.dll 也启用了.. 错误信息-: SMT
我正在尝试使用 Amazon 的 SES/SMTP 发送电子邮件,但出现以下错误: javax.mail.MessagingException:无法连接到 SMTP 主机:email-smtp.us-
在我的Mac终端上,我试图通过telnet将smtp.gmail.com转换为port 587。 在Google Apps(设置为管理Dreamhost域)上,我已配置了中继,如下所示: "Allow
理论上,Request For Comments (RFC) 集包含开发人员构建 SMTP 客户端需要知道的一切。然而,要知道哪些 RFC 需要考虑,哪些可以忽略并不总是那么容易。 有没有人有 RFC
MT 支持 SMTP SendMail,还是我坚持使用 MFMailComposeViewController?现在,我可以使用它(MFMailComposeViewController),但是当我添
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 10年前关
我正在尝试通过 BizTalk SMTP 发送端口发送消息。具体来说,我正在通过编排的“稍后指定”端口发送消息。我的目标是使用我选择的附件文件名将消息正文附加到已发送的电子邮件。 但是,无论我尝试什么
我正在编写一个通过有效的 GMail 用户 ID 和密码发送邮件的应用程序。 我只是想在 Windows XP 命令行上模拟 SMTP 连接,当我在 465 端口 telnet smtp.gmail.
关于从应用程序通过 GMails SMTP 服务器发送的电子邮件被标记为垃圾邮件的问题已经有很多讨论。 阅读其他帖子我无法弄清楚我的问题。我的电子邮件最终仍然是 SPF 中性的。 在我的 *(捕获所有
我是一名优秀的程序员,十分优秀!