I am trying to write HTML with some CSS to send it in an email. The email is sent through Go command line execution. But its returning errors regarding CSS properties while sending email.
I am getting errors for properties like, background: rgb(255, 255, 255)
or padding
for some of its properties it returns "not found" error in terminal.
<div style="margin: 0; padding: 0; background: #ffffff; font-family: Montserrat, sans-serif; font-size: 16px; color: #313131">
Above is a chunk of html and css properties I am using.
Following is the code to send email through command line:
package utils
import(
"bytes"
"html/template"
"os/exec"
"fmt"
)
type EmailRequest struct{
EmailTo string
EmailSubject string
EmailBody string
}
func (request *EmailRequest) EmailSend(notificationTemplateData interface{}) (bool, error) {
subject, errParse := ParseTemplate(request.EmailSubject, notificationTemplateData)
body, errParse := ParseTemplate(request.EmailBody, notificationTemplateData)
if errParse != nil{
return false, errParse
}
err := ExecuteCommand("echo \""+body+" \" | mail -s \"$(echo \" "+subject+"
MIME-version: 1.0;
Content-Type: text/html;charset=\"UTF-8\";
\")\" "+request.EmailTo)
if err != nil {
return false, err
}
return true, nil
}
func ParseTemplate(templateHtml string, data interface{}) (string, error) {
var body string
t, err := template.New("test").Parse(templateHtml)
if err != nil {
return body, err
}
buf := new(bytes.Buffer)
if err = t.Execute(buf, data); err != nil {
return body, err
}
body = buf.String()
return body, nil
}
func ExecuteCommand(command string) error{
cmd := exec.Command("sh", "-c",command)
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return err
}
fmt.Println("Result: " + out.String())
return nil
}
I have an editor where a customer can configure its custom template. Obviously, the customer can add any CSS properties. So with random properties it will lead to an error.
What I have understood from the above error is that it throws errors for random CSS properties or is there any CSS rules to send email through go command line?
Edited:
Following is the Error that I am getting in terminal while running EmailSend() function.
sh:
padding: not found
sh:
background: not found