No, the sending code does not look right. The EHLO domain is not right, the code does not check for DATA response, and there should be an empty line between message headers and the message body.
If it has worked at some point, it was only because the server was lax and allowed slightly malformed and/or unsafe messages through.
The
emailResp() function is completely bogus.
There are two types of responses from the SMTP server:
NNN DASH TEXTSTRING CR LF NNN SPACE TEXTSTRING CR LFwhere
NNN is the three decimal digit status code,
TEXTSTRING consists of zero or more ASCII codes 9 or 32-126 inclusive,
DASH is ASCII code 45,
SPACE is ASCII code 32,
CR is ASCII code 13, and
LF is ASCII code 10.
For each response (with the exact same
NNN), the final line will be of the latter (space) form. If there is more than that final line, the preceding lines will use the former (dash) form (so you can simply ignore the dash form lines). Each
emailResp() call should receive exactly one response, consisting of zero or more dash form lines, and exactly one space form. It should also return the decimal value of
NNN from that last line. (You can use negative codes and codes 0-99 for errors, so that 100 and above are SMPT response codes.)
If you are sending a message to
recipient@example.com from
account@domain, the client should:
- Connect to the SMTP server using the appropriate port, and wait for a response. The response should be 220.
- Send "EHLO domain\r\n", and wait for a response. The response should be 220.
- Send "AUTH LOGIN\r\n", and wait for a response. The response should be 334.
- Send "username\r\n" (where username is Base64-encoded form of the username), and wait for a response. The response should be 334.
- Send "password\r\n" (where password is Base64-encoded form of the password), and wait for a response. The response should be 235.
- Send "MAIL FROM:<account@domain>\r\n", and wait for a response. The response should be 250.
- Send "RCPT TO:<recipient@example.com>\r\n", and wait for a response. The response should be 250.
- Send "DATA\r\n", and wait for a response. The response should be 354.
- Send each header line, for example "Subject: This is the message subject\r\n". (Every header line must end with "\r\n".)
- Send empty line between headers and message body, "\r\n".
- Send message body. If the body is not empty, it must end with "\r\n".
- Send ".\r\n", and wait for a response. The response should be 250.
- Send "QUIT\r\n", and wait for a response. The response should be 221.
Also note that each line must not exceed 998 characters (plus CR LF), but limiting to 78 characters (plus CR LF) would be even better. Servers will check
domain against the list of domains the specified
username is allowed to send, and will reject the
MAIL FROM command if they do not match. In the case where the server knows about
domain users, it may even check that
username and
account match. So, you cannot just use whatever domain in a EHLO greeting!