]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/smtp/smtp.factor
smtp: Fix issues with sending an email using Outlook's smtp server.
[factor.git] / basis / smtp / smtp.factor
index 043d6d81dcc2612e68c427791858cd224fdd4b5b..e00c3e2b416b4a1e1435669e1b70ddf4c1ffd711 100644 (file)
@@ -17,6 +17,9 @@ SINGLETON: no-auth
 TUPLE: plain-auth username password ;
 C: <plain-auth> plain-auth
 
+TUPLE: login-auth username password ;
+C: <login-auth> login-auth
+
 : <smtp-config> ( -- smtp-config )
     smtp-config new ; inline
 
@@ -129,7 +132,7 @@ ERROR: smtp-transaction-failed < smtp-error ;
 
 : check-response ( response -- )
     dup code>> {
-        { [ dup { 220 235 250 221 354 } member? ] [ 2drop ] }
+        { [ dup { 220 235 250 221 334 354 } member? ] [ 2drop ] }
         { [ dup 400 499 between? ] [ drop smtp-server-busy ] }
         { [ dup 500 = ] [ drop smtp-syntax-error ] }
         { [ dup 501 = ] [ drop smtp-command-not-implemented ] }
@@ -149,13 +152,21 @@ GENERIC: send-auth ( auth -- )
 
 M: no-auth send-auth drop ;
 
+: >smtp-base64 ( str -- str' )
+    utf8 encode >base64 >string ;
+
 : plain-auth-string ( username password -- string )
-    [ "\0" prepend ] bi@ append utf8 encode >base64 >string ;
+    [ "\0" prepend ] bi@ append >smtp-base64 ;
 
 M: plain-auth send-auth
     [ username>> ] [ password>> ] bi plain-auth-string
     "AUTH PLAIN " prepend command get-ok ;
 
+M: login-auth send-auth
+    "AUTH LOGIN" command get-ok
+    [ username>> >smtp-base64 command get-ok ]
+    [ password>> >smtp-base64 command get-ok ] bi ;
+
 : auth ( -- ) smtp-config get auth>> send-auth ;
 
 : encode-header ( string -- string' )
@@ -214,7 +225,10 @@ ERROR: invalid-header-string string ;
     [
         get-ok
         helo get-ok
-        smtp-config get tls?>> [ start-tls get-ok send-secure-handshake ] when
+        smtp-config get tls?>> [
+            start-tls get-ok send-secure-handshake
+            helo get-ok
+        ] when
         auth
         dup from>> extract-email mail-from get-ok
         dup to>> [ extract-email rcpt-to get-ok ] each