go-gomail / gomail

The best way to send emails in Go.
MIT License
4.32k stars 572 forks source link

gomail body doesn't show the newline #90

Closed chinglinwen closed 7 years ago

chinglinwen commented 7 years ago

code: https://github.com/chinglinwen/maild

Say following code

I've try print the body value, it's included newline, but the received mail body doesn't have newline

func mail(from, subject, body string, receivers []string) error {
    m := gomail.NewMessage()
    m.SetHeader("From", from)
    m.SetHeader("To", receivers...)
    m.SetHeader("Subject", subject)
    m.SetBody("text/html", body)
    d := gomail.NewDialer(*smtpAddr, *smtpPort, *smtpUser, *smtpPass)
    return d.DialAndSend(m)
}

use smtp port 587

version: gopkg.in/gomail.v2

chinglinwen commented 7 years ago

re-produce step (the following is how I do it) :

I've print the body inside maild (incase prevent other issues), it show body is correctly transfer to gomail

  1. deploy maild on localhost

  2. execute following testing shell code:

    
    email () {
    curl -s -F "receiver=$1" \
    -F "subject=$2" \
    -F "body=$3" \
    http://localhost:3001/
    }

receiver="wzlwen@qq.com" body="[2017-06-19_11:29:54] - restart spider-go-api [2017-06-19_11:29:54] - all service is ok. [2017-06-19_11:31:06] - checks done. [2017-06-19_11:54:26] - checks done. [2017-06-19_11:54:36] - restart spider-go-api [2017-06-19_11:54:38] - spider-go-api is STOPPED, sent to wzlwen@qq.com [2017-06-19_11:54:38] - checks done. [2017-06-19_11:55:36] - restart spider-go-api [2017-06-19_11:55:37] - spider-go-api is STOPPED, sent to wzlwen@qq.com [2017-06-19_11:55:37] - checks done."

email "$receiver" "app is $status" "$body"

chinglinwen commented 7 years ago

It's okay, I change SetBody("text/html", body) to SetBody("text/plain", body), fixed this issue.