-
Notifications
You must be signed in to change notification settings - Fork 61
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
Extract address from "to", "from", "cc", etc. #114
Comments
Here's what I've put together to solve this problem for us. defp address([h | t]) do
[address(h)] ++ address(t)
end
defp address([]) do
[]
end
defp address({ _name, address }) do
address
end
defp address(string) when is_binary(string) do
case Regex.run(~r/.+ <(.+)>/, string) do
nil ->
string
[_, address] ->
address
end
end |
Digging deeper I found https://github.com/DockYard/elixir-mail/blob/master/lib/mail/parsers/rfc_2822.ex#L178-L184 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've run into an issue when using
gen_smtp
where providing an address that's a tuple or contains a name causes the SMTP server (AWS SES in this case) to return an invalid email error. The fix is to extract the address from the tuple/string with name. I'm curious if introducing something likeget_address(message, header)
makes sense for this project. I'd expect this to be a common problem for folks.Here's an example of the problem I'm referring to.
You can fix the the problem by making both
from
andto
plain addresses instead of the name/address combo. However, theFrom
andTo
headers now won't contain the name. This puts the burden on the users ofmail
to figure this out.My proposal is to provide a
get_address/2
function that would provide this functionality.We've implemented something similar in our project and I'd be happy to provide a PR.
The text was updated successfully, but these errors were encountered: