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

func (email *Email) Send(client *SMTPClient) not goroutine safe #13

Closed
rongfengliang opened this issue Nov 22, 2020 · 3 comments
Closed

Comments

@rongfengliang
Copy link

i do some test with keepalive,but got some wrong (smtp server with mailhog )

2020/11/22 01:42:01 [SMTP 172.21.0.1:40294] [PROTO: RCPT] In RCPT state
2020/11/22 01:42:01 [SMTP 172.21.0.1:40294] [PROTO: RCPT] Got unknown command for RCPT state: '&{MAIL FROM:<[email protected]> MAIL FROM:<[email protected]>}'
2020/11/22 01:42:01 [SMTP 172.21.0.1:40294] Sent 26 bytes: '500 Unrecognised command\r\n'
2020/11/22 01:42:01 [SMTP 172.21.0.1:40294] Received 31 bytes: 'RCPT TO:<[email protected]>\r\nRSET\r\n'

some links https://github.com/rongfengliang/golang-email-learning/blob/master/main.go#L15

@xhit
Copy link
Owner

xhit commented Nov 22, 2020

The keep-alive implementation is not safe. You need to make your program safe.

A suggestion is open a connection, and use a goroutine to send a NOOP command every X seconds to avoid disconnection from server.

Commands to SMTP server is one command at time by connection, so use the NOOP and send emails if you are sure the client is not used by another goroutine. You can reset the time for NOOP if you send an email.

@xhit
Copy link
Owner

xhit commented Nov 22, 2020

Also. If you use the keep-alive implementation and you not send NOOP or emails in a short time, the server will disconnect you, and you need to reconnect again before send an email.

@rongfengliang
Copy link
Author

@xhit tks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants