go-smtp-mock
go-smtp-mock copied to clipboard
[BUG] Email address with name is considered invalid
New bug checklist
- [x] I have updated
smtpmock
to the latest version - [x] I have read the Contribution Guidelines
- [x] I have read the documentation
- [x] I have searched for existing GitHub issues
Bug description
I am trying to send an email with this sender address John Doe<[email protected]>
. I think this should also be a valid email address format to be supported by smtpmock.
Currently I am getting back this error: SMTP response: 501 MAIL FROM requires valid email address
This applies to both, sender and receiver address.
Complete output when running smtpmock, including the stack trace and command used
server := smtpmock.New(smtpmock.ConfigurationAttr{
PortNumber: 2525,
LogToStdout: true,
LogServerActivity: true,
})
if err := server.Start(); err != nil {
t.Fatal(err)
}
INFO: 2023/02/18 22:03:23.182796 SMTP response: 220 Welcome
truetime="2023-02-18T22:03:23+01:00" level=info msg="Sending mail to SMTP"
INFO: 2023/02/18 22:03:23.182969 SMTP request: EHLO localhost
INFO: 2023/02/18 22:03:23.183380 SMTP response: 250 Received
INFO: 2023/02/18 22:03:23.183462 SMTP request: MAIL FROM:<John Doe<[email protected]>>
INFO: 2023/02/18 22:03:23.183590 SMTP response: 501 MAIL FROM requires valid email address
time="2023-02-18T22:03:23+01:00" level=error msg="MAIL FROM requires valid email address"
@codedge Thanks! It is out of minimal scope. But I agree, seems we should implement it. https://www.rfc-editor.org/rfc/rfc5322#section-3.4
Hi,
I encouraged the same problem. What is the priority of this one? @bestwebua
Can it be solved by updating the emailRegexPattern
in consts.go
?
More failing cases (Should be valid):
John <[email protected]>
<[email protected]>
Hello, @cengizhancaliskan! Thanks for your interest! Yes, it can be solved here:
- Main regex,
emailRegexPattern
: https://github.com/mocktools/go-smtp-mock/blob/d29f933cc7f5f26966000fb5e2fe5cca8f1c165a/consts.go#L56
Also we need to update handlerMailfrom
and handlerRcptto
dependent methods:
-
handlerMailfrom#mailfromEmail
, composite regexvalidMailromComplexCmdRegexPattern
:
https://github.com/mocktools/go-smtp-mock/blob/d29f933cc7f5f26966000fb5e2fe5cca8f1c165a/consts.go#L68
https://github.com/mocktools/go-smtp-mock/blob/d29f933cc7f5f26966000fb5e2fe5cca8f1c165a/handler_mailfrom_test.go#L218
-
handlerRcptto#rcpttoEmail
, composite regexvalidRcpttoComplexCmdRegexPattern
:
https://github.com/mocktools/go-smtp-mock/blob/d29f933cc7f5f26966000fb5e2fe5cca8f1c165a/consts.go#L69
https://github.com/mocktools/go-smtp-mock/blob/d29f933cc7f5f26966000fb5e2fe5cca8f1c165a/handler_rcptto_test.go#L319