Comments (13)
lol, yes you are correct re Mikrotik.
The below is for a Java client.
I like your approach, my only question would be why would you add a switch (multipleRcptto )?
Why not just let it function in multiple mode as a normal/standard way ?
The client can send 1 message when the server is in multiple mode : no problem
from go-smtp-mock.
@dandare100 Thanks for java client examples ❤️ I think it can be configured behaviour against hardcoded. It will bring more flexibility and more context even from configuration, for example:
smtpmock.New(smtpmock.ConfigurationAttr{
MultipleRcptto: true,
MultipleMessageReceiving: true,
NotRegisteredEmails: []string{"[email protected]"},
})
Also we should folowing current 'configuring flow' to save our main feature - 'Configurable multithreaded RFC compatible SMTP server'. Agree? 😃
If it okay I'll prepare to 2.x.x migration and will start developing this feature 👨💻
from go-smtp-mock.
@dandare100 Hahaha, I knew this question would be asked someday) Agree! Let's back for this point at the beginning of October 🍻
from go-smtp-mock.
👍
This is essential for testing emailer implementations. It should indeed be a string slice in sequential order of RCPT
commands.
e.g. if the emailer implementation is sending the email to two recipents "a" and "b" on the "example" domain, then the RcpttoRequest()
method on a Message
should return:
[]string{"RCPT TO:<[email protected]>", "RCPT TO:<[email protected]>"}
from go-smtp-mock.
@bestwebua I'm happy to give this a go, if you can point me to the bits of the code that would need changing. The current implementation seems to do some "writing" that involves some significant indirection that I would rather not spend the time trying to unravel if you could just explain it to me?
from go-smtp-mock.
It seems like the client sends the first one and then each subsequent one after receiving a 250 Received from the server.
For my quick use on my project I just did this
// Writes handled RCPTTO result to session, message. Always returns true
func (handler *handlerRcptto) writeResult(isSuccessful bool, request, response string) bool {
session, message := handler.session, handler.message
if !isSuccessful {
session.addError(errors.New(response))
}
message.rcpttoRequests = append(message.rcpttoRequests, request)
message.rcpttoResponse, message.rcptto = response, isSuccessful
session.writeResponse(response, handler.configuration.responseDelayRcptto)
return true
}
and
// Structure for storing the result of SMTP client-server interaction. Context-included
// commands should be represented as request/response structure fields
type Message struct {
heloRequest, heloResponse string
mailfromRequest, mailfromResponse string
rcpttoResponse string
rcpttoRequests []string
dataRequest, dataResponse string
msgRequest, msgResponse string
rsetRequest, rsetResponse string
helo, mailfrom, rcptto, data, msg, rset, quitSent bool
}
I had no need for separate messages in my case. I understand your requirement to have multiple messages :-)
When adding the rcpt's, something to be careful of is the clearMessage call below in handler_rcptto.go.
I commented it out because my needs were still met.
I suspect that clear to have something to do with the "-multipleMessageReceiving" option but I didn't look into it further.
// Main RCPTTO handler runner
func (handler *handlerRcptto) run(request string) {
handler.clearError()
//I scheme it's because of the mutlimessage disting in the config
//handler.clearMessage()
if handler.isInvalidRequest(request) {
return
}
handler.writeResult(true, request, handler.configuration.msgRcpttoReceived)
}
from go-smtp-mock.
@dandare100 Thanks for your knowledge sharing, Mark! I'll play with some stdlib SMTP clients from ruby, python and go to make sure that it is exactly expected multiple rcpt to
behaviour. Have you screened logs from mikrotik built-in smtp client, am I right?
multipleMessageReceiving
it's about ability to send multiple messages during one session. And entry point for this case is multipleMessageReceiving
enabled flag and RSET
command, please look on this test example:
Lines 189 to 267 in 03e6fbe
Line 231 in 03e6fbe
What you think about next steps of implementation?:
- Add flag
multipleRcptto
- Change
Message
structure to be able to save slice of strings:
type Message struct {
heloRequest, heloResponse string
mailfromRequest, mailfromResponse string
rcpttoRequestResponse [][]string // new fileld with [["request", "response"]]
dataRequest, dataResponse string
msgRequest, msgResponse string
rsetRequest, rsetResponse string
helo, mailfrom, rcptto, data, msg, rset, quitSent bool
}
- Leave current behaviour for case when
multipleRcptto
isfalse
- When
multipleRcptto
istrue
we need to record allRCPT TO
request/response pairs until receive succesful response and next smtp command has been passed. Also message clearing flow should be used for case whenRCPT TO
will passed afterDATA
and upper or when has been usedRSET
P.S.: View for successful send messages we can add later. I believe it should be a slice of "successful mesages" where all multiple messages will be represented as independent messages. For instance, we have 1 single message and 1 multiple message with 2 receivers. Total count of this successful messages should be 3.
from go-smtp-mock.
Good points, I agree
from go-smtp-mock.
@dandare100, @benjamin-rood Already in latest (2.0.0
) release 🚀
from go-smtp-mock.
@dandare100 Hahaha, I knew this question would be asked someday) Agree! Let's back for this point at the beginning of October 🍻
Cool, cheers
from go-smtp-mock.
@benjamin-rood Sounds good. Okay, but let's complete race condition fix firsly ;)
from go-smtp-mock.
Mates, @dandare100, @benjamin-rood! Could somebody provide an example of multiple RCPT TO
command example? I expect that it should be somesing like:
RCPT TO:<[email protected],[email protected]>
RCPT TO:[email protected],[email protected]
And it will produce 2 different messages with different RCPT TO contexts.
from go-smtp-mock.
from go-smtp-mock.
Related Issues (20)
- [FEATURE] Support for multiple mails over one connection HOT 2
- [FEATURE] Ability to use address literal as valid HELO command argument HOT 7
- [FEATURE] Optional message purge when retrieving messages HOT 6
- [BUG] Race condition detected when run in test files HOT 11
- [QUESTION] Increase test coverage for handler type HOT 3
- [BUG] Autobuilds of smtpmock binary doesn't set version notes HOT 1
- [BUG] Invalid email can be passed as argument for MAIL FROM, RCPT TO commands
- [BUG] BrokenImport, could not import (no required module provides package) HOT 3
- [BUG] Data race between `newMessage()` and `Messages()` HOT 18
- [BUG] Email address with name is considered invalid HOT 3
- [FEATURE] Easy asserts for mail data
- [BUG] Cannot use localhost as domain in MAIL FROM HOT 1
- [FEATURE] Ability to drop client connection before run SMTP-session
- [FEATURE] Logging to testing logger HOT 1
- [BUG] RSET resets already sent message HOT 4
- [BUG] 2.3.0 broke message reading... HOT 2
- [FEATURE] Ability to specify dropping connection for first n attempts for each SMTP command
- [FEATURE] Ability to shutdown server with SIGQUIT
- [FEATURE] Ability to read server messages context HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-smtp-mock.