2015-05-09 16 views
16

Desidero poter utilizzare il pacchetto gmailR per inviare report HTML generati da R tramite email in linea (non come allegati). Non riesco nemmeno a inviare un'email HTML di base utilizzando gmailr. Ho tentato, senza successo, il seguente e bisogno di aiuto:Invia messaggio HTML utilizzando gmailr

library(gmailr) 
gmail_auth("oauth.token.json", scope = "compose") 

test_email <- mime() %>% 
to("[email protected]") %>% 
from("[email protected]") %>% 
subject("This is a subject") 
test_email$body <- "I wish <b>this</b> was bold" 
send_message(test_email) 
RISULTATO: Messaggio invia correttamente, ma il corpo è sotto gli occhi di testo - non HTML


Tentativo 2

test_email <- mime() %>% 
to("[email protected]") %>% 
from("[email protected]") %>% 
subject("This is a subject") %>% 
html_body("I wish <b>this</b> was bold") 
test_email$body 
RISULTATO: test_email $ body è NULL


Tentativo 3

test_email <- mime() %>% 
to("[email protected]") %>% 
from("[email protected]") %>% 
    subject("This is a subject") 
test_email$body <- html_body("I wish <b>this</b> was bold") 
RISULTATO: Errore in MIME $ parti: $ operatore non è valido per i vettori atomiche


Tentativo 4

test_email <- mime() %>% 
to("[email protected]") %>% 
from("[email protected]") %>% 
subject("This is a subject") 
test_email$parts <- c(html_body("I wish <b>this</b> was bold"),text_body("plain")) 
Result: ERROR in mime $ parti: $ operatore non è valido per i vettori atomici
+1

sembra che questo sia correlato al problema a cui si fa riferimento qui: https://github.com/jimhester/gmailr/issues/9 –

+0

Mentre questo non risponde al tuo problema relativo a gmailr, ti consiglio di dare a mailR uno scatto che supporta facilmente l'invio di e-mail in formato HTML (https://github.com/rpremraj/mailR). –

+0

I tentativi 3 e 4 chiaramente non sono validi. Come afferma la documentazione, i primi argomenti per text_body() e html_body() sono un oggetto mime, non una stringa di testo. Può essere usato per impostare il corpo html o testo su un oggetto mime, in questo modo: text_body (test_email, "stringa di testo normale") – WhiteViking

risposta

2

Bene - questo è quello che ho provato:

library(gmailr) 
gmail_auth('mysecret.json', scope = 'compose') 

test_email <- mime() %>% 
to("[email protected]") %>% 
from("[email protected]") %>% 
subject("This is a subject") %>% 
html_body("<html><body>I wish <b>this</b> was bold</body></html>") 
send_message(test_email) 

E voilà (gmail tedesco ...) enter image description here

Sembra come il trucco era semplicemente quello di mettere in real HTML - tra cui <html> e <body> - a fai capire a gmail.