(m *Message)
| 62 | } |
| 63 | |
| 64 | func (c *SMTPClient) send(m *Message) error { |
| 65 | var smtpAuth smtp.Auth |
| 66 | if c.Username != "" || c.Password != "" { |
| 67 | switch c.AuthMethod { |
| 68 | case SMTPAuthLogin: |
| 69 | smtpAuth = &smtpLoginAuth{c.Username, c.Password} |
| 70 | default: |
| 71 | smtpAuth = smtp.PlainAuth("", c.Username, c.Password, c.Host) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | hostWithPort := net.JoinHostPort(c.Host, strconv.Itoa(c.Port)) |
| 76 | |
| 77 | // create mail instance |
| 78 | var yak *mailyak.MailYak |
| 79 | if c.TLS { |
| 80 | var tlsErr error |
| 81 | yak, tlsErr = mailyak.NewWithTLS(hostWithPort, smtpAuth, nil) |
| 82 | if tlsErr != nil { |
| 83 | return tlsErr |
| 84 | } |
| 85 | } else { |
| 86 | yak = mailyak.New(hostWithPort, smtpAuth) |
| 87 | } |
| 88 | |
| 89 | if c.LocalName != "" { |
| 90 | yak.LocalName(c.LocalName) |
| 91 | } |
| 92 | |
| 93 | if m.From.Name != "" { |
| 94 | yak.FromName(m.From.Name) |
| 95 | } |
| 96 | yak.From(m.From.Address) |
| 97 | yak.Subject(m.Subject) |
| 98 | yak.HTML().Set(m.HTML) |
| 99 | |
| 100 | if m.Text == "" { |
| 101 | // try to generate a plain text version of the HTML |
| 102 | if plain, err := html2Text(m.HTML); err == nil { |
| 103 | yak.Plain().Set(plain) |
| 104 | } |
| 105 | } else { |
| 106 | yak.Plain().Set(m.Text) |
| 107 | } |
| 108 | |
| 109 | if len(m.To) > 0 { |
| 110 | yak.To(addressesToStrings(m.To, true)...) |
| 111 | } |
| 112 | |
| 113 | if len(m.Bcc) > 0 { |
| 114 | yak.Bcc(addressesToStrings(m.Bcc, true)...) |
| 115 | } |
| 116 | |
| 117 | if len(m.Cc) > 0 { |
| 118 | yak.Cc(addressesToStrings(m.Cc, true)...) |
| 119 | } |
| 120 | |
| 121 | // add regular attachements (if any) |
no test coverage detected