(m *Message)
| 92 | } |
| 93 | |
| 94 | func (e *Email) Send(m *Message) (err error) { |
| 95 | // Message header |
| 96 | m.buffer = bytes.NewBuffer(make([]byte, 256)) |
| 97 | m.buffer.Reset() |
| 98 | m.boundary = random.String(16) |
| 99 | m.writeHeader("MIME-Version", "1.0") |
| 100 | m.writeHeader("Message-ID", m.ID) |
| 101 | m.writeHeader("Date", time.Now().Format(time.RFC1123Z)) |
| 102 | m.writeHeader("From", m.From) |
| 103 | m.writeHeader("To", m.To) |
| 104 | if m.CC != "" { |
| 105 | m.writeHeader("CC", m.CC) |
| 106 | } |
| 107 | if m.Subject != "" { |
| 108 | m.writeHeader("Subject", m.Subject) |
| 109 | } |
| 110 | // Extra |
| 111 | for k, v := range e.Header { |
| 112 | m.writeHeader(k, v) |
| 113 | } |
| 114 | m.writeHeader("Content-Type", "multipart/mixed; boundary="+m.boundary) |
| 115 | m.buffer.WriteString("\r\n") |
| 116 | |
| 117 | // Message body |
| 118 | if m.BodyText != "" { |
| 119 | m.writeText(m.BodyText, "text/plain") |
| 120 | } else if m.BodyHTML != "" { |
| 121 | m.writeText(m.BodyHTML, "text/html") |
| 122 | } else { |
| 123 | m.writeBoundary() |
| 124 | } |
| 125 | |
| 126 | // Inlines/attachments |
| 127 | for _, f := range m.Inlines { |
| 128 | m.writeFile(f, "inline") |
| 129 | } |
| 130 | for _, f := range m.Attachments { |
| 131 | m.writeFile(f, "attachment") |
| 132 | } |
| 133 | m.buffer.WriteString("--") |
| 134 | m.buffer.WriteString(m.boundary) |
| 135 | m.buffer.WriteString("--") |
| 136 | |
| 137 | // Dial. Port 465 is SMTPS (implicit TLS) per IANA and always uses |
| 138 | // TLS. Other ports connect plaintext and opportunistically upgrade |
| 139 | // to STARTTLS only if the server advertises it — if the server |
| 140 | // doesn't, the connection stays in the clear. Operators that |
| 141 | // require TLS must use port 465. |
| 142 | c, err := e.dial() |
| 143 | if err != nil { |
| 144 | return |
| 145 | } |
| 146 | defer c.Quit() |
| 147 | |
| 148 | // Authenticate |
| 149 | if e.Auth != nil { |
| 150 | if err = c.Auth(e.Auth); err != nil { |
| 151 | return |
nothing calls this directly
no test coverage detected