Quesofat
Quesofat

Reputation: 1531

Sending email to a gmail account via SMTP

I'm trying to make a SMTP client library and am trying to send email via the command line first.

250 SMTPUTF8
EHLO gmail.com
write to 0x7fb0e6c16130 [0x7fb0ea011a03] (37 bytes => 37 (0x25))
0000 - 17 03 03 00 20 3f a5 65-6f 8a a3 b8 a7 13 7e 70   .... ?.eo.....~p
0010 - 57 a1 7b ca c1 4b 25 56-39 b5 df d6 c4 b7 49 c1   W.{..K%V9.....I.
0020 - 32 f2 f4 5a c5                                    2..Z.
read from 0x7fb0e6c16130 [0x7fb0ea00d803] (5 bytes => 5 (0x5))
0000 - 17 03 03 00 c2                                    .....
read from 0x7fb0e6c16130 [0x7fb0ea00d808] (194 bytes => 194 (0xC2))
0000 - 23 b5 8f 8e 31 26 8a dd-98 ce fd 73 58 8b e4 f5   #...1&.....sX...
0010 - 0a d6 8d 7b a8 a0 97 fb-ef 48 84 9b 10 f4 58 2b   ...{.....H....X+
0020 - 65 0c 61 29 17 f7 41 0b-c4 59 8a 87 87 4b f7 b9   e.a)..A..Y...K..
0030 - 7a 68 8c f8 1b ec 05 bb-fa 97 dc 81 76 ba 12 86   zh..........v...
0040 - ed a6 6f 06 44 74 e1 80-4c 24 37 a4 06 a6 40 9d   ..o.Dt..L$7...@.
0050 - c9 57 b2 2d 6c a7 fe cf-bb 7b 32 4e 01 f2 65 94   .W.-l....{2N..e.
0060 - b5 1f f9 aa eb 73 c6 b8-6c 93 71 89 2c 84 83 ad   .....s..l.q.,...
0070 - 73 bb 5a 8b 63 c4 5a 94-d9 65 fa 2e 3b 1a 3d 21   s.Z.c.Z..e..;.=!
0080 - f8 6f 97 f0 61 1d 13 b3-ee 68 cf ed 92 aa dd e0   .o..a....h......
0090 - 86 16 e3 14 71 ef b0 28-74 ec fa ba ad 9f e2 6d   ....q..(t......m
00a0 - 05 c1 39 7a 65 71 21 34-e8 a7 be d1 6c 39 68 42   ..9zeq!4....l9hB
00b0 - 84 a2 8d 9e 7c 03 57 49-6f 5b c1 af 78 2d 72 e5   ....|.WIo[..x-r.
00c0 - 47 67                                             Gg
250-mx.google.com at your service, [2800:e2:37f:ecc6:9426:2eed:fdd4:795b]
250-SIZE 157286400
250-8BITMIME
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
MAIL FROM:[email protected]
write to 0x7fb0e6c16130 [0x7fb0ea011a03] (46 bytes => 46 (0x2E))
0000 - 17 03 03 00 29 1a 31 f6-c0 39 da 57 95 3e 85 0c   ....).1..9.W.>..
0010 - 48 86 29 1c a5 c2 80 cb-40 79 ef fa 66 dd e7 10   H.)[email protected]...
0020 - 8e dd 14 d2 f3 c8 07 98-ff 06 68 8b 4d b2         ..........h.M.
read from 0x7fb0e6c16130 [0x7fb0ea00d803] (5 bytes => 5 (0x5))
0000 - 17 03 03 00 44                                    ....D
read from 0x7fb0e6c16130 [0x7fb0ea00d808] (68 bytes => 68 (0x44))
0000 - 4a 7d f0 e2 01 00 00 eb-8b c0 82 70 fd 09 1a 50   J}.........p...P
0010 - 3b b3 fb ab 8a a1 83 df-af cd c8 bb 96 4f eb 19   ;............O..
0020 - 38 19 fa 4c 28 5d 75 f9-a4 d5 20 38 c4 f3 b6 db   8..L(]u... 8....
0030 - cd 44 3f 36 6a 8c f6 79-38 2e d3 2f b2 c4 4d 91   .D?6j..y8../..M.
0040 - 51 e8 2f ff                                       Q./.
555 5.5.2 Syntax error. d7si1665405vsj.297 - gsmtp

The problem is no matter what email address I use I get a syntax error. What am I doing wrong?

Upvotes: 1

Views: 150

Answers (1)

anx
anx

Reputation: 173

Missing brackets enclosing your source mailbox.

The first step in the procedure is the MAIL command.

  MAIL FROM:<reverse-path> [SP <mail-parameters> ] <CRLF>

The portion of the first or only argument contains the source mailbox (between "<" and ">" brackets), which can be used to report errors (see Section 4.2 for a discussion of error reporting). If accepted, the SMTP server returns a "250 OK" reply.

-- from RFC 5321 Section 3.3 (emphasis mine)

Change this

MAIL FROM:[email protected]

Into this:

MAIL FROM:<[email protected]>

That being said..

I'm trying to make a SMTP client library

Please don't do that! Almost every programming language has such libraries already, most often even in the respective stdlib. And the authors of those have generally carefully considered more edge cases than you and I ever could. Do not reinvent the wheel, especially if handling mail (where it is all too easy to cause interoperability issues or new vectors for spam/abuse).

Upvotes: 2

Related Questions