Format of EML files used by System.Net.Mail.MailMessage and Microsoft SMTP Server - mime

I'm trying to wrap my head around the EML files I see generated by System.Net.Mail.MailMessage and generated or consumed by Microsoft's SMTP Server. I've been reading RFCs 5322 and 5321 and I'm trying to make sense of the format.
Granted, the majority of the EML files I see are adherent to the message format described in 5322 (or 2322 or 822, however good MS stuck to the standards, I don't know). However, I can't quite decide if the top portion of the file (the X-Sender and X-Receiver lines) constitute the "envelope" as described by 5321.
I guess my questions are:
Is there documentation for the portion of this file with X-Sender/X-Receiver lines (above the message contents)?
Are there other "commands" that can be expected in this section?
Is this a "standard" across the board? i.e. can I expect an EML file that is generated by System.Net.Mail.MailMessage to be parsed correctly in any standard SMTP server?

No, there isn't any documentation. This is something only done by the IIS SMTP service, and there aren't any other commands that I'm aware of.
However, the email is still RFC2822 compliant. It just prepends the message with some X-Headers that are still RFC compliant, but are recognized the IIS SMTP service.
The IIS SMTP service will use the X-Sender value as the SMTP MAIL FROM value, and the X-Receiver as the RCPT TO value.

Related

Postfix triggering a script

I've installed Postfix as mail server following this tutorial.
I've no problem sending emails. I would like to use the mail server to trigger a shell script each time a mail is received. To do so I've added the following code to the 'aliases' file:
myemailaccount: "|/home/pi/Desktop/TestScript/TestShell.sh"
The shell is also quite simple, I only try to generate a text file in order to know if the shell has been executed :
#!/bin/sh
echo "Let's check if this works!" > Output.txt
So I've tried to send an email to 'myemailaccount#gmail.com' waiting to see the file 'Output.txt' to be generated but nothing happens. If I run the shell from the terminal, no probs, it works.
It's seems that you have setup Postfix to send emails thru Gmail.
To receive emails from outside is another painfully road with a lot of tricky parts.
To receive emails you need a Reverse IP from you ISP and check if port 25 is visible outside. Email servers check for this ports to issue SMTP protocol verifications.
Nowadays, you also need a valid certificate to operate TLS and SSL over you server.
You can use Let's Encrypt free ones.
Don't forget to setup DKIM, SPF and MX stuff in your DNS.
You also need to setup Dovecot or Courier servers:
https://docs.gitlab.com/ee/administration/reply_by_email_postfix_setup.html
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-postfix-e-mail-server-with-dovecot
If you are confused why do you need both Dovecot and Postfix, Read This!
But you can check this solution, if you don't need too much tech:
Execute script when new email arrives (Postfix / Dovecot)

Is there a detailed specification for Outlook 365 IMAP? Which RFC's does it comply with?

Does anyone know if there is a specification for Outlook 365 that would describe their IMAP implementation in detail.
In particular, Which RFC's they comply with. For example, there are many Updates to RFC 3501. RFC 3501 list these RFC's in the update section. 466, 4469, 4551, 5032, 5182, 5738,6186, 6858, 7817, 8314, 8437, 8474
In addition, I'm having problems with how Outlook manages IMAP folder's. Outlook is sending the LIST command but not the LSUB command. LSUB is only send manually if the IMAP Folders outlook option is used. This is different from how other IMAP clients work.
Outlook 365, like all IMAP servers, advertises its extensions when you connect to it. Here's an example where I send the capability command to ask it:
$ openssl s_client -connect outlook.office365.com:993 -crlf
[…]
* OK The Microsoft Exchange IMAP4 service is ready. [Zm5vcmQK]
a capability
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
a OK CAPABILITY completed.
The server almost certainly advertises more extensions after login. The IANA maintains a map from capability name to RFC.
I found that this document
https://learn.microsoft.com/en-us/openspecs/exchange_standards/ms-stanoimap/9e26aea5-bb27-40d2-be9a-c82878c7d567
Provides the best spec for how outlook imap differs from the standard.
I found that Outlook requires the XLIST command to be used in place of the LSUB for folders to be displayed. This is strange since XLISt its NOT listed in the CAPABILITIES string.

Time-Stamping servers API (what signtool uses)

What is the input that (code signing) time stamping servers expect? And what format is the reply?
I've searched VeriSign's site (and more) but found nothing but directions to use tools like signtool. What I want is the ability to create something like signtool from scratch.
To create signtool from scratch, start with the osslsigncode source, as it does roughly the same thing.
For RFC 3161 timestamp servers (supported by signtool), the request and response formats are publicly documented and supported by Openssl. If you use Wireshark to examine the network packets sent by signtool to the timestamp server you'll find them very similar to the openssl ts output.

How to setup a mail server?

I want anyone who send a email to test#example.com, and the server could get the mail and so I can use some server side scripting language like Ruby to parser the content of the email.
Ruby solution would be great.
If you've never set up an smtp server, and you're not willing to dig in and learn a lot, you might want to check out some of the services that offer this kind of ability. I have never used any of these, not sure about quality or pricing aspects.
cloudmailin
mailgun
dispatch
postmark
An alternative to setting up and configuring a mail server is to use a service such as sendgrid or postmark. You point your DNS mx records at them and they will turn inbound messages into JSON documents and post them to you
You can install qmail on your server, and configure it to pipe incoming mail to your domain to the STDIN of your ruby script.
If you haven't done so already, create an MX record for your domain that points to your mailserver's IP. Then, login to the server as root, then install qmail by following the instructions at http://lifewithqmail.org/lwq.html#installation
Configure qmail to accept incoming mail for *#yourdomain.tld (catchall), and forward all incoming mail to the script at /home/yourhomedirectory/yourscript.sc:
add the following line to /var/qmail/control/me:
hostname.yourdomain.tld
add the following line to /var/qmail/control/defaultdomain:
yourdomain.tld
addd the following line to /var/qmail/control/virtualdomains
yourdomain.tld:yourusername
add the following line to /var/qmail/control/rcphosts:
yourdomain.tld
restart qmail:
qmailctl stop
qmailctl stat
Logout of the server, then log back in again as yourusername. Create a file /home/yourusername/.qmail-default, consisting of the following line:
| /home/yourhomedirectory/yourscript.sc
Create /home/yourhomedirectory/yourscript.sc script to process incoming mail. Enable executable permissions on the script for all users:
chmod a+x /home/yourhomedirectory/yourscript.sc
That's all there is to it. Incoming mail to your domain will be piped by qmail to this script's STDIN.
Install and configure an SMTP server. SMTP servers can usually be configured quite extensively, what to do with mails that should be deliverd locally. One such option would be to deliver the mail locally by invoking a ruby script. Popular SMTP servers are postfix, courier and qmail. The details about how to setup the mail server depends on which one you use.

How can I get FTP response information about each command easily, instead of reading a full RFC 959?

I'm trying to write a perfectly standard FTP server.
My server received 'SYST' command. And
I tried on sending the response message "remote system is Mac OS X.\r\n".
but FTP client does not work.
FTP client is /usr/bin/ftp in Macintosh HD.
more badly,
there in no responses information about each command in the RFC 959??
since I use english as second language, it's very hard to read RFC 959.
Could someone give me some link with response information?
Here is related image.
https://docs.google.com/document/d/15ktF514CH4E00-Ab0QwPAaXRk6G4eIbDcsRJuhOyAuE/edit
RFC 959 specifies all you need to know, probably you misread the description, or don't send the result code at the beginning of the reply. On the page 49 there is a list of commands and possible reply codes.

Resources