Git Product home page Git Product logo

Comments (13)

jlinnosa avatar jlinnosa commented on May 22, 2024

I made a PR implementing these modifications.

from go-simple-mail.

xhit avatar xhit commented on May 22, 2024

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.

jlinnosa avatar jlinnosa commented on May 22, 2024

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.

xhit avatar xhit commented on May 22, 2024

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.

xhit avatar xhit commented on May 22, 2024

unify-attach branch is the branch to test this.

from go-simple-mail.

hiendv avatar hiendv commented on May 22, 2024

Hi, @xhit
Do you have any plan to support custom ContentID (cid)?

from go-simple-mail.

xhit avatar xhit commented on May 22, 2024

@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.

xhit avatar xhit commented on May 22, 2024

@hiendv please fill another issue and I will respond on that.

from go-simple-mail.

jlinnosa avatar jlinnosa commented on May 22, 2024

@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.

jlinnosa avatar jlinnosa commented on May 22, 2024

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.

xhit avatar xhit commented on May 22, 2024

Thanks, I will work on that maybe tomorrow.

from go-simple-mail.

xhit avatar xhit commented on May 22, 2024

Added in #35

Not a breaking change.

from go-simple-mail.

jlinnosa avatar jlinnosa commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.