Send embedded svg instead of pdf attachment.
This commit is contained in:
parent
093bc9af97
commit
804bfed173
14
main.go
14
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -125,10 +126,15 @@ func fetch() {
|
||||||
log.Print("No mail host set, returning")
|
log.Print("No mail host set, returning")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f, err := os.Open("Rplots.pdf")
|
f, err := os.Open("Rplot001.svg")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error opening Rplots.pdf: ", err)
|
log.Fatal("Error opening Rplot001.svg: ", err)
|
||||||
}
|
}
|
||||||
|
data, err := ioutil.ReadAll(f)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Cannot read Rplot001.svg: ", err)
|
||||||
|
}
|
||||||
|
data64 := base64.StdEncoding.EncodeToString(data)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
for _, r := range conf.Recipients {
|
for _, r := range conf.Recipients {
|
||||||
email := mailyak.New(fmt.Sprintf("%s:%d", conf.MailHost, conf.MailPort),
|
email := mailyak.New(fmt.Sprintf("%s:%d", conf.MailHost, conf.MailPort),
|
||||||
|
@ -138,10 +144,12 @@ func fetch() {
|
||||||
msg := "Covid dashboard update for " + time.Now().Format("Monday, January 2 2006")
|
msg := "Covid dashboard update for " + time.Now().Format("Monday, January 2 2006")
|
||||||
email.Subject(msg)
|
email.Subject(msg)
|
||||||
email.Plain().Set(msg)
|
email.Plain().Set(msg)
|
||||||
email.Attach("dashboard.pdf", f)
|
email.HTML().Set(`<html><body><img src="data:image/svg+xml;base64,`+data64+`"/></body></html>`)
|
||||||
err = email.Send()
|
err = email.Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Error sending email: ", err)
|
log.Print("Error sending email: ", err)
|
||||||
|
} else {
|
||||||
|
log.Print("Sent email to ", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
rcode.go
2
rcode.go
|
@ -42,7 +42,7 @@ pr3 <- ggplot(qrate, aes(x=date, y=value)) + geom_line()+scale_y_continuous(labe
|
||||||
|
|
||||||
pr4 <- ggplot(trate, aes(x=date, y=value)) + geom_line()+scale_y_continuous(labels = scales::percent, position='right')+labs(y='Positive Rate')+coord_cartesian(ylim=c(0,0.04))+ggtitle('New York')+theme(plot.title=element_text(hjust = 0.5))
|
pr4 <- ggplot(trate, aes(x=date, y=value)) + geom_line()+scale_y_continuous(labels = scales::percent, position='right')+labs(y='Positive Rate')+coord_cartesian(ylim=c(0,0.04))+ggtitle('New York')+theme(plot.title=element_text(hjust = 0.5))
|
||||||
|
|
||||||
pdf(width=8,height=16)
|
svg(width=8,height=16)
|
||||||
grid.arrange(p1, p2, pr1, pr2, p3, p4, pr3, pr4, ncol=2, top=format(d[[nrow(d),1]], "%B %d %Y"))
|
grid.arrange(p1, p2, pr1, pr2, p3, p4, pr3, pr4, ncol=2, top=format(d[[nrow(d),1]], "%B %d %Y"))
|
||||||
dev.off()
|
dev.off()
|
||||||
`
|
`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user