|
@@ -2,19 +2,20 @@ package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"bufio"
|
|
"bufio"
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "io/ioutil"
|
|
|
"log"
|
|
"log"
|
|
|
"os"
|
|
"os"
|
|
|
"regexp"
|
|
"regexp"
|
|
|
"strings"
|
|
"strings"
|
|
|
- "time"
|
|
|
|
|
|
|
|
|
|
- mail "github.com/xhit/go-simple-mail"
|
|
|
|
|
- //"github.com/xhit/go-simple-mail/v2"
|
|
|
|
|
|
|
+ "github.com/sendgrid/sendgrid-go"
|
|
|
|
|
+ "github.com/sendgrid/sendgrid-go/helpers/mail"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
//SEE https://github.com/xhit/go-simple-mail
|
|
//SEE https://github.com/xhit/go-simple-mail
|
|
|
|
|
|
|
|
-// CheckAddressMaillist
|
|
|
|
|
|
|
+// CheckAddressMaillist ...
|
|
|
func CheckAddressMaillist(maillist string) string {
|
|
func CheckAddressMaillist(maillist string) string {
|
|
|
strings.Replace(maillist, "noreply@aske-futurskill.com;", "", -1)
|
|
strings.Replace(maillist, "noreply@aske-futurskill.com;", "", -1)
|
|
|
maillistArray := strings.Split(maillist, ";")
|
|
maillistArray := strings.Split(maillist, ";")
|
|
@@ -34,7 +35,7 @@ func CheckAddressMaillist(maillist string) string {
|
|
|
return newMaillist
|
|
return newMaillist
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// GetMailtoFile
|
|
|
|
|
|
|
+// GetMailtoFile ...
|
|
|
func GetMailtoFile(filename string) []string {
|
|
func GetMailtoFile(filename string) []string {
|
|
|
file, err := os.Open(filename)
|
|
file, err := os.Open(filename)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -51,36 +52,88 @@ func GetMailtoFile(filename string) []string {
|
|
|
return txtlines
|
|
return txtlines
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// PrepareMail ...
|
|
|
|
|
-func PrepareMail(email string, htmlBody string, imageList []string) *mail.Email {
|
|
|
|
|
- email := mail.NewMSG()
|
|
|
|
|
-
|
|
|
|
|
- email.SetFrom("From Support ASkE <noreply@aske-futurskill.com>")
|
|
|
|
|
- email.AddTo("support@aske-futurskill.com")
|
|
|
|
|
- email.AddBcc(maillingList)
|
|
|
|
|
- email.SetSubject("[TEST] MAILLING")
|
|
|
|
|
|
|
+// FileHTMLToString ...
|
|
|
|
|
+func FileHTMLToString(filehtml string) string {
|
|
|
|
|
+ b, err := ioutil.ReadFile(filehtml) // just pass the file name
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Print(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ return string(b)
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- email.SetBody(mail.TextHTML, htmlBody)
|
|
|
|
|
- for image := range imageList {
|
|
|
|
|
- email.AddInline(string.Split(imageList, ';')[0], string.Split(imageList, ';')[1])
|
|
|
|
|
|
|
+func main() {
|
|
|
|
|
+ filemail := os.Args[1]
|
|
|
|
|
+ subject := os.Args[2]
|
|
|
|
|
+ filehtml := os.Args[3]
|
|
|
|
|
+
|
|
|
|
|
+ from := mail.NewEmail("Support ASkE", "noreply@aske-futurskill.com")
|
|
|
|
|
+ subject := subject
|
|
|
|
|
+ to := mail.NewEmail("Example User", "test@example.com")
|
|
|
|
|
+ plainTextContent := "and easy to do anywhere, even with Go"
|
|
|
|
|
+ htmlContent := "<strong>and easy to do anywhere, even with Go</strong>"
|
|
|
|
|
+ message := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent)
|
|
|
|
|
+ client := sendgrid.NewSendClient(os.Getenv("SENDGRID_API_KEY"))
|
|
|
|
|
+ response, err := client.Send(message)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Println(err)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fmt.Println(response.StatusCode)
|
|
|
|
|
+ fmt.Println(response.Body)
|
|
|
|
|
+ fmt.Println(response.Headers)
|
|
|
}
|
|
}
|
|
|
- return email
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
|
+func main() {
|
|
|
|
|
+ filemail := os.Args[1]
|
|
|
|
|
+ subject := os.Args[2]
|
|
|
|
|
+ filehtml := os.Args[3]
|
|
|
|
|
+
|
|
|
|
|
+ bodyHTML := FileHTMLToString(filehtml)
|
|
|
|
|
+ maillingList := GetMailtoFile(filemail)
|
|
|
|
|
+ for _, email := range maillingList {
|
|
|
|
|
+ mailjetClient := mailjet.NewMailjetClient(os.Getenv("c4832eafdd5b13635a5d1273cb998d3f"), os.Getenv("ad985e178e340b85e192097b02026429"))
|
|
|
|
|
+ messagesInfo := []mailjet.InfoMessagesV31{
|
|
|
|
|
+ mailjet.InfoMessagesV31{
|
|
|
|
|
+ From: &mailjet.RecipientV31{
|
|
|
|
|
+ Email: "noreply@aske-futurskill.com",
|
|
|
|
|
+ Name: "Support ASkE",
|
|
|
|
|
+ },
|
|
|
|
|
+ To: &mailjet.RecipientsV31{
|
|
|
|
|
+ mailjet.RecipientV31{
|
|
|
|
|
+ Email: email,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ Subject: subject,
|
|
|
|
|
+ HTMLPart: bodyHTML,
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+ messages := mailjet.MessagesV31{Info: messagesInfo}
|
|
|
|
|
+ res, err := mailjetClient.SendMailV31(&messages)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Fatal(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ fmt.Printf("Data: %+v\n", res)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+*/
|
|
|
|
|
+/*
|
|
|
func main() {
|
|
func main() {
|
|
|
|
|
|
|
|
- filename := os.Args[1]
|
|
|
|
|
|
|
+ filemail := os.Args[1]
|
|
|
|
|
+ subject := os.Args[2]
|
|
|
|
|
+ filehtml := os.Args[3]
|
|
|
|
|
|
|
|
smtpServ := xmail.NewSMTPClient()
|
|
smtpServ := xmail.NewSMTPClient()
|
|
|
- server.Host = "in-v3.mailjet.com"
|
|
|
|
|
- server.Port = 587
|
|
|
|
|
- server.Username = "c4832eafdd5b13635a5d1273cb998d3f"
|
|
|
|
|
- server.Password = "ad985e178e340b85e192097b02026429"
|
|
|
|
|
- server.Encryption = mail.EncryptionTLS
|
|
|
|
|
|
|
+ smtpServ.Host = "in-v3.mailjet.com"
|
|
|
|
|
+ smtpServ.Port = 587
|
|
|
|
|
+ smtpServ.Username = "c4832eafdd5b13635a5d1273cb998d3f"
|
|
|
|
|
+ smtpServ.Password = "ad985e178e340b85e192097b02026429"
|
|
|
|
|
+ smtpServ.Encryption = mail.EncryptionTLS
|
|
|
|
|
|
|
|
// smtpServ.Authentication = mail.AuthPlain
|
|
// smtpServ.Authentication = mail.AuthPlain
|
|
|
|
|
|
|
|
- smtpServ.KeepAlive = false
|
|
|
|
|
|
|
+ smtpServ.KeepAlive = true
|
|
|
smtpServ.ConnectTimeout = 10 * time.Second
|
|
smtpServ.ConnectTimeout = 10 * time.Second
|
|
|
smtpServ.SendTimeout = 10 * time.Second
|
|
smtpServ.SendTimeout = 10 * time.Second
|
|
|
|
|
|
|
@@ -89,10 +142,12 @@ func main() {
|
|
|
log.Fatal(err)
|
|
log.Fatal(err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- maillingList := GetMailtoFile()
|
|
|
|
|
- for email := range maillingList {
|
|
|
|
|
- email := PrepareMail(email)
|
|
|
|
|
- err = email.Send(smtpClient)
|
|
|
|
|
|
|
+ bodyHTML := FileHTMLToString(filehtml)
|
|
|
|
|
+ maillingList := GetMailtoFile(filemail)
|
|
|
|
|
+ for _, email := range maillingList {
|
|
|
|
|
+ fmt.Println(email)
|
|
|
|
|
+ mail := PrepareMail(email, subject, bodyHTML)
|
|
|
|
|
+ err = mail.Send(smtpClient)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log.Println(err)
|
|
log.Println(err)
|
|
@@ -101,3 +156,4 @@ func main() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+*/
|