Closed suntong closed 12 months ago
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.
Thanks for the confirmation. I'll make a try...
This could be handled locally fairly easily too:
if err := m.To(strings.Split("a1@gmail.com,a2@gmail.com", ",")...); err != nil {
indeed!
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.
Yeah, agree.
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.
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:
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.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