Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Req] Interface that accept To/CC with a single string #152

Closed
suntong opened this issue Nov 9, 2023 · 7 comments · Fixed by #155
Closed

[Feature Req] Interface that accept To/CC with a single string #152

suntong opened this issue Nov 9, 2023 · 7 comments · Fixed by #155
Assignees
Labels
enhancement New feature or request WIP Work is in progress

Comments

@suntong
Copy link

suntong commented Nov 9, 2023

Is your feature request related to a problem? Please describe.

Please consider adding/allowing passing a single string to To/CC. Currently there is an extra check preventing it:

failed to set To address: failed to parse mail address "a1@gmail.com,a2@gmail.com", mail: expected single address, got ",a2@gmail.com"

When using

if err := m.To("a1@gmail.com,a2@gmail.com"); err != nil {

in https://go-mail.dev/getting-started/introduction/#hl-5-13

Reason being:

  • It is perfectly fine to set the "To:" header to something like "Alice <alice@example.com>, Bob <bob@example.com>, Eve <eve@example.com>" in plain email, so such extra checking is too restrictive.
  • I understand that there might be extra checking on the email address format checking, but since the basic text based unix email doesn't check it, such extra checking can be optional, IMHO. After all, if the user made mistakes in their to/cc email address, they will know eventually.
  • And the most important thing is, to add more recipients, I have to change my Go code to do that, whereas the common sense/practice is to change data, not to change code, when covering different cases.

Describe the solution you'd like

Adding/allowing passing a single string to To/CC.

I can work on PR for that.

Describe alternatives you've considered

No response

Additional context

No response

@suntong suntong added the enhancement New feature or request label Nov 9, 2023
@wneessen
Copy link
Owner

wneessen commented Nov 9, 2023

Hi @suntong,

thanks for the feature request. I see your need here and I think it might be a good addition to go-mail. To not break any current code, I suggest something like m.ToFromString() and m.CcFromString(). If you'd like a provide a PR, that'll be appreciated. Otherwise I'll put this request on the todo list for the next release.

@wneessen wneessen added the TODO label Nov 9, 2023
@suntong
Copy link
Author

suntong commented Nov 9, 2023

Thanks for the confirmation. I'll make a try...

@wneessen wneessen added WIP Work is in progress and removed TODO labels Nov 9, 2023
suntong added a commit to suntong/go-mail that referenced this issue Nov 10, 2023
@james-d-elliott
Copy link
Contributor

This could be handled locally fairly easily too:

if err := m.To(strings.Split("a1@gmail.com,a2@gmail.com", ",")...); err != nil {

@suntong
Copy link
Author

suntong commented Nov 10, 2023

indeed!

@wneessen
Copy link
Owner

wneessen commented Nov 10, 2023

Thanks for the PR @suntong, but I feel that adding complexity SetAddrHeader should not be the desired solution. As either To(), Cc() and Bcc() already accept slices of strings, @james-d-elliott's solution should probably be preferred by just adding helper methods like:

func (m *Msg) ToFromSimpleString(v string) error {
    return m.To(strings.Split(v)...);
}

or something similar. This let's us stay true with the KISS principle.

@suntong
Copy link
Author

suntong commented Nov 10, 2023

Yeah, agree.

@suntong suntong closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2023
@suntong
Copy link
Author

suntong commented Nov 10, 2023

should probably be preferred by just adding helper methods like ...
Otherwise I'll put this request on the todo list for the next release.

That'd be great, if possible.

Reopen it again, and feel free to close it anytime.

@suntong suntong reopened this Nov 10, 2023
wneessen added a commit that referenced this issue Nov 10, 2023
Added new methods `ToFromString()`, `CcFromString()` and `BccFromString()` in msg.go file to handle strings of comma-separated email addresses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request WIP Work is in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants