last day (14 days later) » 

8:36 AM
1
Q: Twisted SMTP Server - getting full recipient list, and header data?

Steve HallSo after a huge amount of patience from, and gratitude towards @Jean-PaulCalderone, I now have a twisted mail server that supports (yet to be tested) TLS! I can telnet to it, issue my EHLO, MAIL FROM etc etc, and dump the message to file, as per the code snippet below (the 2 classes below are rip...

 
afaik, RCPT TO only accept 1 recipient, normally you need to repeat RCPT TO: <email> in order to send to multiple recipients. Perhaps in your case you need to do a for/loop to send multiple times?
 
Hi @Anzel... I do issue multiple RCPT TO: commands in my telnet session - but the "Recipients" object in the code above seems to have lost all but the last one...
 
can you provide some logging or how you debug "Recipients" object? maybe then we can look at it more closely
 
Cant really provide a lot... As I say, it's based on the emailserver.tac in the link above. I then modified receivedheader based on this: twistedmatrix.com/trac/browser/tags/releases/twisted-14.0.0/…
 
um... that would be hard, but just by simple comparison, seems you have put \n\n at end of for_, will replace \n\n with ; helps?
 
8:36 AM
Further investigation suggests my analysis of the issue wasn't quite right. It looks like my multiple RCPT to's are being accepted, and are in the recipients array... but from that point, somehow the message is split/duplicated to create a single sent message per recipient... :(
 
can you show how the message is split/duplicated? I have a feeling that in your list of Recipients you somehow emit each mail to each recipient... whereas it should be email to a list of recipients with the same mail
Hi steve
 
Hi Anzel.... I've added server output to the original question.... this shows out Im trying to send a single message to multiple recipients.... but then it gets split
 
let me have a quick look
do you have content in the email? i mean email body
 
just the text "Today is the 21st Oct (still)"
so I do an ehlo, then mail from, 2* rcpt to, data (Today is....) then a .
 
but your log shows the email is completed. what you see they are split/duplicated?
or you want to group all recipients in 1xresponse?
 
8:43 AM
I want a single message, with multiple recipients.
that server output to me suggests 2 * messages
at the top of that server output, the 2 recipients are grouped
 
ah, i see. then it's about how you handle self.lines, however this behaviour is absolutely fine. think about if one of the recipients' emails are undelivered....
it's same as doing multiple RCPT TO from telnet
 
???
 
??? on self.lines or?
 
I just dont quite understand your answer. I do multiple rcpt to statements. Twisted's "do_DATA" method in mail.py produces the "Receiving message for delivery..." statement, which shows both of the addresses in a single message.... but then validateTo in my server's ConsoleMessageDelivery is calling ConsoleMessage (in the return lamda statement) for each address. surely the validateTo just needs to validate all the addresses, then pass the full header to ConsoleMessage?
 
that's technically correct, but i don't see you try/except any error during lamda statement. and the mail will only be received when all lambda completes ==> which means you're receiving each mail from each recipient
think about each lamba => self.lines.append()
 
8:55 AM
yeah I kinda get it... think I need to experiment a bit to get a better grasp of process / method flow
 
That's fine, especially you just found out you haven't done any code wrong.... apart from try/except the received mail part.
Good Luck :)
 
Cheers!
 
I will try to post an answer so we can close this question
 
I think what I need .... Can you offer a way of moving the lambda statement from validateto, to receivedheader, while still passing the header info through?
I think maybe the init for Console message needs to take a 2nd param "HeaderData".... and the at the end of receivedHeader do return lambda: ConsoleMessage("Client:......")

But then what validateTo should return - I've no idea!
 
hold on, so you want to bypass validate_to and lambda from receivedheader?
basically receivedheader will do nothing against the received "body", so it won't catch whether the mail is actually emitted.
 
9:04 AM
I think that's the way forward... hang on, let me double check something
 
validate_to is only a function to trigger the ConsoleMessage() whenever a recipient emits
 
so validateTo gets called upon submission of an RCPT TO from the telnet client session
 
Yes.
 
and that's the problem - triggering the lambda Console Message call at that point
I want to gather all my recipients together
 
so alternatively you can try writing a pipeline which group and collect all lines before triggering ConsoleMessage
in one go
then you will get your desire result
 
9:07 AM
no idea of pipelines....
 
but mind you, it is kind of cheating yourself to believe this behaviour, and it doesn't change the fact how smtp works
when i say pipeline, think of it like: I will send all validate_to ConsoleMessage(), and you store all from,to,header,body in that instance, and when all mail emits, you do a final call to ConsoleMessage() with well formatted message
 
perhaps... what I need is to see more of the full SMTP header in the resulting message
do you know how to do that with Twisted SMTP/
 
So you want to include mail header on each message received?
 
yeah for now...
 
hold on, let me check that source code
 
9:18 AM
thanks
 
um... twisted doc is shit
but look at this:
http://twistedmatrix.com/documents/8.2.0/api/twisted.protocols.basic.LineReceiver.html#rawDataReceived
try using rawDataReceived and you should be able to parse with header content.
 
9:33 AM
I'll give it a look, thanks again Anzel.... If you can scribble an answer for the original q, including the above (but dont mention the docs being shit!!) - that'd be great, thanks!
 
 
2 hours later…
11:29 AM
Lol... sure. Good luck with your journey :)
 

last day (14 days later) »