[racket] (smtp-send-message ...) with #:tls-encode
Or, if instead you're wanting to connect to Gmail's SMTP server (not
Exchange) as your script suggests:
Then (although I haven't tried it) probably you want to connect to
port 465 encrypted from the git go. In which case I think you would
pass to smtp-send-message `ssl-connect' for #:tcp-connect and #f for
#:tls-encode. Meaning, connect to port 465 encrypted in the first
place. I think. As to whether Gmail can use AUTH PLAIN as provided by
the stock net/smtp smpt-send-message, or it requires AUTH LOGIN or
something else entirely, I don't know.
One useful thing you can do is un-comment the printf in net/smtp's
`log' function and observe the back-and-forth with the SMTP server.
This is for example how I noticed that the hosted Exchange Server was
expecting AUTH LOGIN.
I hope this helps. If you're still stuck let me know and I can try a
log in to Gmail's SMTP myself, assuming that's your goal here and not
Exchange.
On Tue, Mar 8, 2011 at 4:55 AM, Stephen De Gabrielle
<spdegabrielle at gmail.com> wrote:
> I'm still getting no joy with this.
>
> I've attached my test script, and will try on a different network (in case
> it's my proxy server doing the damage)
>
> -:(-
> Welcome to DrRacket, version 5.1 [3m].
> Language: racket; memory limit: 128 MB.
> "Failed with reason::#(struct:exn:fail:network tcp-connect: connection to
> smtp.gmail.com, port 465 failed (at step 6: No connection could be made
> because the target machine actively refused it.; errno=10061)
> #<continuation-mark-set>)"
> ---
>
>
> On Tue, Mar 8, 2011 at 8:20 AM, Stephen De Gabrielle
> <spdegabrielle at gmail.com> wrote:
>>
>> Thanks Greg,
>>
>> I'll test your patch against the Exchange server I'm wanting to connect
>> to.
>> S.
>>
>> On Mon, Mar 7, 2011 at 9:20 PM, Greg Hendershott
>> <greghendershott at gmail.com> wrote:
>>>
>>> > Does anyone have an example of using #:tls-encode (net/smtp)?
>>>
>>> No, in fact I'm seeing it fail today with an SMTP server that requires
>>> TLS on port 587.
>>>
>>> The reason seems to be that the server is expecting AUTH LOGIN whereas
>>> net/smtp only does AUTH PLAIN.
>>>
>>> I was able to get it to work (with this particular server) by making a
>>> local copy of smtp-send-message from net/smtp-unit.rkt and modifying
>>> lines 96-103:
>>>
>>> (when auth-user
>>> (log "auth\n")
>>> (fprintf w "AUTH PLAIN ~a"
>>> ;; Encoding adds CRLF
>>> (base64-encode
>>> (string->bytes/latin-1
>>> (format "~a\0~a\0~a" auth-user auth-user auth-passwd))))
>>> (check-reply r 235 w))
>>>
>>> to be this instead:
>>>
>>> (when auth-user
>>> (if tls-encode
>>> (begin
>>> (log "auth login\n")
>>> (fprintf w "AUTH LOGIN\r\n")
>>> (check-reply r 334 w)
>>> (fprintf w "~a" ;encoding adds CRLF
>>> (base64-encode
>>> (string->bytes/latin-1 auth-user)))
>>> (check-reply r 334 w)
>>> (fprintf w "~a" ;encoding adds CRLF
>>> (base64-encode
>>> (string->bytes/latin-1 auth-passwd)))
>>> (check-reply r 235 w))
>>> (begin
>>> (log "auth plain\n")
>>> (fprintf w "AUTH PLAIN ~a" ;encoding adds CRLF
>>> (base64-encode
>>> (string->bytes/latin-1
>>> (format "~a\0~a\0~a" auth-user auth-user
>>> auth-passwd))))
>>> (check-reply r 235 w))))
>>>
>>> i.e. I tried to keep the AUTH PLAIN case while providing AUTH LOGIN on
>>> the assumption it will always be wanted when doing TLS. I don't deeply
>>> know the SMTP protocol. This is based on me observing one specific
>>> server and guessing what would work. That said, I hope this may help.
>>>
>>>
>>> On Fri, Feb 4, 2011 at 7:51 AM, Stephen De Gabrielle
>>> <spdegabrielle at gmail.com> wrote:
>>> > Hi,
>>> >
>>> > Does anyone have an example of using #:tls-encode (net/smtp)?
>>> >
>>> > Cheers,
>>> >
>>> > Stephen
>>> >
>>> > --
>>> > Stephen De Gabrielle
>>> > stephen.degabrielle at acm.org
>>> > Telephone +44 (0)20 85670911
>>> > Mobile +44 (0)79 85189045
>>> > http://www.degabrielle.name/stephen
>>> >
>>> > _________________________________________________
>>> > For list-related administrative tasks:
>>> > http://lists.racket-lang.org/listinfo/users
>>
>>
>>
>> --
>>
>> --
>> Stephen De Gabrielle
>> stephen.degabrielle at acm.org
>> Telephone +44 (0)20 85670911
>> Mobile +44 (0)79 85189045
>> http://www.degabrielle.name/stephen
>>
>
>
>
> --
>
> --
> Stephen De Gabrielle
> stephen.degabrielle at acm.org
> Telephone +44 (0)20 85670911
> Mobile +44 (0)79 85189045
> http://www.degabrielle.name/stephen
>
>