<div dir="ltr"><div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)">Amigos de R, </div><div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)">
<br></div><div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)">Sei que essa questão volta algumas vezes na lista mas estou empacado. Estou fazendo um data management de um projeto em que consiste em repetidas vezes, tipo toda semana, verificar quantos voluntários entraram no proejto, dados inconsistentes, dados ausentes e coisas assim. Então, eu consegui fazer um script para esse fim em que gera um arquivo com algumas tabelas e graficos. </div>
<div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)"><br></div><div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)">Agora eu gostaria de incluir nesse script o envio de um email pra mim mesmo com esse arquivo, para que eu possa verificar e depois encaminhar para os outros participantes. Sei que existe o sendmailR, mas não estou conseguindo fazer funcionar. Encontrei um catatau de gente referindo o mesmo erro em diversos diferentes foruns: </div>
<div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)"><br></div><div class="gmail_default"><div class="gmail_default"><font color="#000066" face="courier new, monospace">> sendmail(from, to, subject, body,control=list(smtpServer="<a href="http://ASPMX.L.GOOGLE.COM">ASPMX.L.GOOGLE.COM</a>"))</font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace">Erro em socketConnection(host = server, port = port, blocking = TRUE) : </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> não é possível abrir a conexão</font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace">Além disso: Mensagens de aviso perdidas:</font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace">In socketConnection(host = server, port = port, blocking = TRUE) :</font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> <a href="http://ASPMX.L.GOOGLE.COM:25">ASPMX.L.GOOGLE.COM:25</a> cannot be opened</font></div><div style="color:rgb(0,0,102);font-family:'courier new',monospace">
<br></div></div><div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)"><br></div><div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)">
Depois, consegui encontrar essa função em um dos foruns. O autor fala que funciona, mas comigo tem dado um erro de conectividade e eu não sabendo como dar a volta nesse erro. Será que tem alguma relação com o proxy?</div>
<div class="gmail_default"><div class="gmail_default"><font color="#000066" face="courier new, monospace"><br></font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace">> send.email</font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace">function(to, from, subject, </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> message, attachment=NULL, </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> username, password, </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> server="<a href="http://smtp.gmail.com:587">smtp.gmail.com:587</a>", </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> confirmBeforeSend=TRUE){ </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> # to: a list object of length 1. Using list("Recipient" = "<a href="mailto:recip@somewhere.net">recip@somewhere.net</a>") will send the message to the address but </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> # the name will appear instead of the address. </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> # from: a list object of length 1. Same behavior as 'to' </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> # subject: Character(1) giving the subject line. </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> # message: Character(1) giving the body of the message </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> # attachment: Character(1) giving the location of the attachment </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> # username: character(1) giving the username. If missing and you are using Windows, R will prompt you for the username. </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> # password: character(1) giving the password. If missing and you are using Windows, R will prompt you for the password. </font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"> # server: character(1) giving the smtp server. </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> # confirmBeforeSend: Logical. If True, a dialog box appears seeking confirmation before sending the e-mail. This is to </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> # prevent me to send multiple updates to a collaborator while I am working interactively. </font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"> </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (!is.list(to) | !is.list(from)) stop("'to' and 'from' must be lists") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (length(from) > 1) stop("'from' must have length 1") </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (length(to) > 1) stop("'send.email' currently only supports one recipient e-mail address") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (length(attachment) > 1) stop("'send.email' can currently send only one attachment") </font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"> if (length(message) > 1){ </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> stop("'message' must be of length 1") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> message <- paste(message, collapse="\\n\\n") </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> } </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (is.null(names(to))) names(to) <- to </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (is.null(names(from))) names(from) <- from </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (!is.null(attachment)) if (!file.exists(attachment)) stop(paste("'", attachment, "' does not exist!", sep="")) </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (missing(username)) username <- winDialogString("Please enter your e-mail username", "") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (missing(password)) password <- winDialogString("Please enter your e-mail password", "") </font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"> </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> require(rJython) </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython <- rJython() </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"><br></font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython$exec("import smtplib") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython$exec("import os") </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython$exec("from email.MIMEMultipart import MIMEMultipart") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython$exec("from email.MIMEBase import MIMEBase") </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython$exec("from email.MIMEText import MIMEText") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython$exec("from email.Utils import COMMASPACE, formatdate") </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython$exec("from email import Encoders") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> rJython$exec("import email.utils") </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"><br>
</font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> mail<-c( </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> #Email settings </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("fromaddr = '", from, "'", sep=""), </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("toaddrs = '", to, "'", sep=""), </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "msg = MIMEMultipart()", </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("msg.attach(MIMEText('", message, "'))", sep=""), </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("msg['From'] = email.utils.formataddr(('", names(from), "', fromaddr))", sep=""), </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("msg['To'] = email.utils.formataddr(('", names(to), "', toaddrs))", sep=""), </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("msg['Subject'] = '", subject, "'", sep="")) </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (!is.null(attachment)){ </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> mail <- c(mail, </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("f = '", attachment, "'", sep=""), </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> "part=MIMEBase('application', 'octet-stream')", </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "part.set_payload(open(f, 'rb').read())", </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> "Encoders.encode_base64(part)", </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "part.add_header('Content-Disposition', 'attachment; filename=\"%s\"' % os.path.basename(f))", </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "msg.attach(part)") </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> } </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"><br></font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace">#SMTP server credentials </font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"> mail <- c(mail, </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("username = '", username, "'", sep=""), </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("password = '", password, "'", sep=""), </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"><br>
</font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace">#Set SMTP server and send email, e.g., google mail SMTP server </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> paste("server = smtplib.SMTP('", server, "')", sep=""), </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "server.ehlo()", </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> "server.starttls()", </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "server.ehlo()", </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> "server.login(username,password)", </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "server.sendmail(fromaddr, toaddrs, msg.as_string())", </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> "server.quit()") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"><br></font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> message.details <- </font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"> paste("To: ", names(to), " (", unlist(to), ")", "\n", </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> "From: ", names(from), " (", unlist(from), ")", "\n", </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "Using server: ", server, "\n", </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> "Subject: ", subject, "\n", </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> "With Attachments: ", attachment, "\n", </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> "And the message:\n", message, "\n", sep="") </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"><br></font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (confirmBeforeSend) </font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"> SEND <- winDialog("yesnocancel", paste("Are you sure you want to send this e-mail to ", unlist(to), "?", sep="")) </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> else SEND <- "YES" </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> if (SEND %in% "YES"){ </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> jython.exec(rJython,mail) </font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"> cat(message.details) </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"> } </font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"> else cat("E-mail Delivery was Canceled by the User") </font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace">}</font></div>
<div class="gmail_default"><font color="#000066" face="courier new, monospace"><br></font></div><div class="gmail_default"><font color="#000066" face="courier new, monospace"><div class="gmail_default">from <- list("Recipient" = "<a href="mailto:emmanuel.brasil@gmail.com">emmanuel.brasil@gmail.com</a>")</div>
<div class="gmail_default">to <- list("Recipient" = "<a href="mailto:emmanuel.brasil@gmail.com">emmanuel.brasil@gmail.com</a>")</div><div class="gmail_default">subject <- paste0("Pendencias Nomograma de ",Sys.time())</div>
<div class="gmail_default"><div class="gmail_default">message <- "Mensagem automática com relatório de pendências do projeto Nomograma."</div><div class="gmail_default">attachment <- 'c:/banco/nomograma/Controle_recrutamento.doc'</div>
<div>> send.email(to,from,subject,message,attachment,'<a href="mailto:emmanuel.brasil@gmail.com">emmanuel.brasil@gmail.com</a>','...',confirmBeforeSend=FALSE)<br></div></div></font></div><div class="gmail_default">
<font color="#000066" face="courier new, monospace"><div class="gmail_default">Erro em jython.exec(rJython, mail) : (62, 'Connection refused')</div><div><br></div></font></div><div class="gmail_default" style><font color="#000066" face="courier new, monospace">Qualquer luz é bem vinda. </font></div>
<div class="gmail_default" style><font color="#000066" face="courier new, monospace"><br></font></div><div class="gmail_default" style><font color="#000066" face="courier new, monospace">Abraço forte,</font></div></div><div class="gmail_default" style="font-family:'courier new',monospace;color:rgb(0,0,102)">
<br></div><div><font face="'courier new', monospace" style="background-color:rgb(255,255,255)" color="#000066">Dr. Pedro Emmanuel A. A. do Brasil</font><div><font face="'courier new', monospace" style="background-color:rgb(255,255,255)" color="#000066">Curriculum Lattes:
<span style="text-align:left"><a href="http://lattes.cnpq.br/6597654894290806" target="_blank">http://lattes.cnpq.br/6597654894290806</a></span> <br>Instituto de Pesquisa Clínica Evandro Chagas<br>Fundação Oswaldo Cruz<br>
Rio de Janeiro - Brasil<br>Av. Brasil 4365, <br>CEP 21040-360,<br>Tel 55 21 3865-9648<br>email: <a href="mailto:pedro.brasil@ipec.fiocruz.br" target="_blank">pedro.brasil@ipec.fiocruz.br</a><br>email: <a href="mailto:emmanuel.brasil@gmail.com" target="_blank">emmanuel.brasil@gmail.com</a><br>
<br>---Apoio aos softwares livres<br><a href="http://www.zotero.org" target="_blank">www.zotero.org</a> - gerenciamento de referências bibliográficas. <br><a href="http://www.broffice.org" target="_blank">www.broffice.org</a> ou <a href="http://www.libreoffice.org/" target="_blank">www.libreoffice.org</a> - textos, planilhas ou apresentações.<br>
<a href="http://www.epidata.dk" target="_blank">www.epidata.dk</a> - entrada de dados.<br><a href="http://www.r-project.org" target="_blank">www.r-project.org</a> - análise de dados.<br><a href="http://www.ubuntu.com" target="_blank">www.ubuntu.com</a> - sistema operacional</font></div>
</div>
</div>