go-gomail / gomail

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

Using SetHeaders() adds an extra colon for Subject #95

Closed aletheia7 closed 7 years ago

aletheia7 commented 7 years ago

Test App

package main                                                                                                                                                                                                         

import (                                                                                                                                                                                                             
    "github.com/go-gomail/gomail"                                                                                                                                                                                    
    "os"                                                                                                                                                                                                             
    "fmt"                                                                                                                                                                                                            
    "time"                                                                                                                                                                                                           
)                                                                                                                                                                                                                    

func main() {                                                                                                                                                                                                        
    fmt.Fprintln(os.Stdout, "Good")                                                                                                                                                                                  
    m := gomail.NewMessage()                                                                                                                                                                                         
    m.SetHeader("From", "guy@example.com.com")                                                                                                                                                                       
    m.SetHeader("To", "guy@example.com.com")                                                                                                                                                                         
    m.SetHeader("Subject", "t1")                                                                                                                                                                                     
    m.SetBody("text/plain", "Hello!")                                                                                                                                                                                
    m.WriteTo(os.Stdout)                                                                                                                                                                                             
    m.Reset()                                                                                                                                                                                                        
    m.SetHeaders(map[string][]string{                                                                                                                                                                                
        "From":     {m.FormatAddress("guy@example.com.com", "Sender")},                                                                                                                                              
        "To":       {m.FormatAddress("guy@example.com.com", "The Dude")},                                                                                                                                            
        "Date":     {m.FormatDate(time.Now())},                                                                                                                                                                      
        "Subject:": {"Hello!"},                                                                                                                                                                                      
    })                                                                                                                                                                                                               
    m.SetBody("text/plain", "t1")                                                                                                                                                                                    
    fmt.Fprintln(os.Stdout, "\nBad")                                                                                                                                                                                 
    m.WriteTo(os.Stdout)                                                                                                                                                                                             
    fmt.Println("")                                                                                                                                                                                                  
}

Output

Good                      
Mime-Version: 1.0         
Date: Sat, 05 Aug 2017 20:31:32 -0700                
From: guy@example.com.com 
To: guy@example.com.com   
Subject: t1               
Content-Type: text/plain; charset=UTF-8              
Content-Transfer-Encoding: quoted-printable          

Hello!                    
Bad                       
Mime-Version: 1.0         
From: "Sender" <guy@example.com.com>                 
To: "The Dude" <guy@example.com.com>                 
Date: Sat, 05 Aug 2017 20:31:32 -0700                
Subject:: Hello!          
Content-Type: text/plain; charset=UTF-8              
Content-Transfer-Encoding: quoted-printable          

t1 

Version: 81ebce5c23dfd25c6c67194b37d3dd3f338c98b1

hut8 commented 7 years ago

Isn't this just because you put the colon in yourself?

        "Subject:": {"Hello!"},      

which you did not do in the first version?

aletheia7 commented 7 years ago

Yes. Sorry about that.