-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
Package gomail basic jordan-wright/email wrapper | ||
*/ | ||
package mail // import "github.com/miajio/goemail" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/miajio/goemail | ||
|
||
go 1.21.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package mail | ||
|
||
import ( | ||
"fmt" | ||
"net/textproto" | ||
) | ||
|
||
// Attachment | ||
// is email attachement param type | ||
// Based on the mime/multipart.FileHeader struct | ||
// Attachment contains the name, MIMEHeader, and content of the attachment in question | ||
type Attachment struct { | ||
FileName string // fileName | ||
ContentType string // content type | ||
Header textproto.MIMEHeader // header | ||
Content []byte // content | ||
HTMLRelated bool | ||
} | ||
|
||
func (at *Attachment) setDefaultHeaders() { | ||
contentType := "application/octet-stream" | ||
if len(at.ContentType) > 0 { | ||
contentType = at.ContentType | ||
} | ||
at.Header.Set("Content-Type", contentType) | ||
|
||
if len(at.Header.Get("Content-Disposition")) == 0 { | ||
disposition := "attachment" | ||
if at.HTMLRelated { | ||
disposition = "inline" | ||
} | ||
at.Header.Set("Content-Disposition", fmt.Sprintf("%s;\r\n filename=\"%s\"", disposition, at.FileName)) | ||
} | ||
if len(at.Header.Get("Content-ID")) == 0 { | ||
at.Header.Set("Content-ID", fmt.Sprintf("<%s>", at.FileName)) | ||
} | ||
if len(at.Header.Get("Content-Transfer-Encoding")) == 0 { | ||
at.Header.Set("Content-Transfer-Encoding", "base64") | ||
} | ||
} |
Oops, something went wrong.