Comments (13)
I made a PR implementing these modifications.
from go-simple-mail.
Note: I don't speak english, sorry any mistake.
AddAttachment
and AddInline
actually receives name
because it's possible call the function with the file path to attach only, and the name of file in attachment will be the name of attached file from function.
The name is only a new name that developer want to deliver.
For example, the developer can attach a file like this:
AddAttachment("filepaht/aaa.txt")
And the developer can use a new name for the file
AddAttachment("filepaht/aaa.txt","bbb.txt")
The attachment will be received like bbb.txt
And, the reason this is implemented that form is because a mandatory name will confuse some developers. Send mail with attachment is attach the file only, It's weird to see an implementation where name should change.
And about the mimetype, the package, with the name of file, can capture the mimeType. This not apply when attach a file from bytes and that's why these functions requires mimeType, but I think it's better remove the mimeType parameter and calculate the mimeType from name like other functions.
from go-simple-mail.
One possibility would be to keep AddAttachment
and AddInline
as variadic, but accept mimeType as the second parameter for name. This doesn't change the function signature but offers all the functionality that the other functions provide.
from go-simple-mail.
I have another idea to unify all attachment.
All these methods:
func (email *Email) AddAttachment(file string, name ...string) *Email
func (email *Email) AddAttachmentBase64(b64File, name string) *Email
func (email *Email) AddAttachmentData(data []byte, filename, mimeType string) *Email
func (email *Email) AddInline(file string, name ...string) *Email
func (email *Email) AddInlineBase64(b64File, name, mimeType string) *Email
func (email *Email) AddInlineData(data []byte, filename, mimeType string) *Email
Replace with only one and use a struct to define the attachment.
The struct:
type File struct {
Filepath string
Name string
MimeType string
B64File string
Data []byte
Inline bool
}
The method to unify all:
func (email *Email) Attach(file File) *Email
The commit cb2f478 (non tested and WIP) is based on this idea. Feel free to test.
from go-simple-mail.
unify-attach branch is the branch to test this.
from go-simple-mail.
Hi, @xhit
Do you have any plan to support custom ContentID (cid)?
from go-simple-mail.
@jlinnosa I finished the Unify attachment api. Please see the unify-attach. There are some changes in my last comment
The solution, if not problem with that, will be merged with a new version v3
from go-simple-mail.
@hiendv please fill another issue and I will respond on that.
from go-simple-mail.
@jlinnosa I finished the Unify attachment api. Please see the unify-attach. There are some changes in my last comment
The solution, if not problem with that, will be merged with a new version v3
I'm ok with that. I looked over the changes in the PR and commented on some things.
from go-simple-mail.
You could add a simple shim to implement the current API with this new function so there would be no need to bump the major version. This could be just a new feature. You could then deprecate and remove the old API when releasing v3 later.
from go-simple-mail.
Thanks, I will work on that maybe tomorrow.
from go-simple-mail.
Added in #35
Not a breaking change.
from go-simple-mail.
Like I commented in the PR, please don't keep two separate implementations for the same functionality. That could be a major hindrance in the future.
from go-simple-mail.
Related Issues (20)
- Discarding duplicate email address and setting error HOT 4
- misleading func name: mail.NewSMTPClient() returns a *mail.SMTPServer HOT 1
- Implement reconnect or reconnect helper from #23 HOT 1
- Mail Error on smtp dial: EOF HOT 3
- Race on timeout HOT 3
- No mail send HOT 4
- Mail Error: SMTP Connection timed out HOT 2
- error info inappropriate when auth password need update HOT 2
- Why is it not possible to use proxy? HOT 4
- Export priority type HOT 3
- Using a reader to attach a file HOT 1
- Delivery receipt not working HOT 1
- Use Content-Type: text/x-amp-html HOT 1
- New release HOT 1
- How to track the low level raw SMTP log? HOT 2
- deleted
- [Feature Req] Interface that accept To/CC with a single string HOT 2
- EHLO isn't sent after STARTTLS HOT 3
- Toggle to accept incomplete email address HOT 3
- Support attachments with empty data HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-simple-mail.