Repository navigation
Closed
mirage/colombe
#41Description
I'm trying to use letters to send email via Mailgun (specifically, a sandbox domain that's available on their free tier). I created a simple test program based on the examples in the readme to send a single email to myself:
let body = Letters.Plain {|
Hi there,
This is a test email from https://github.com/oxidizing/letters
Regards,
The Letters team
|}
let send_email () =
let config = (Letters.Config.make
~username:"REDACTED"
~password:"REDACTED"
~hostname:"smtp.mailgun.org"
~with_starttls:true)
in
let sender = "REDACTED - Sandbox Domain" in
let recipients = [Letters.To "[email protected]"] in
let subject = "Test email from mailgun." in
let mail = Letters.build_email ~from:sender ~recipients ~subject ~body in
Printexc.record_backtrace true;
match mail with
| Ok message ->
(try%lwt
Letters.send ~config ~sender ~recipients ~message
with
e ->
Printf.printf "Error. %s\n" (Printexc.to_string e);
Printexc.print_backtrace stdout;
Lwt.return_unit
)
| Error _ -> Printf.printf "Message synthesis failed."; flush stdout; Lwt.return_unit
let () =
Lwt_main.run @@ send_email ()When I tried to run this program, I see:
Error. (Invalid_argument "Malformed input")
Raised at Stdlib__string.index_rec in file "string.ml", line 115, characters 19-34
Called from Sexplib0__Sexp.Printing.index_of_newline in file "src/sexp.ml", line 113, characters 13-47
Is there some way for me to get a clearer picture of what's causing the sending process to fail?
Details:
- I'm using version 4.11.1 of the compiler, version 0.2.1 of
letters, and version 5.4.0 oflwt. - I'm using a Debian instance for development (
Linux 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5+deb10u2 (2019-08-08) x86_64 GNU/Linux)
Things I've tried:
- Changing
with_starttls. - Adding CA certs to the configuration (specifically these).
- Confirming the credentials I received from Mailgun work (their docs provide a python stub one can use for this).
- Running the test program under
strace. I'm not anstraceexpert but it looks like my program was able to successfully connect tosmtp.mailgun.org, sendEHLOandSTARTTLS, and get back a220 Go Aheadbefore things went wrong.
Please let me know if I can help provide more diagnostic information.
Metadata
Metadata
Assignees
Labels
No labels
Activity
dinosaure commentedon Jul 26, 2021
I will take a look on your bug 👍.
dinosaure commentedon Jul 26, 2021
The bug is about
mailgun. Indeed, it does not strictly follow the RFC 4954 which describe the 334 response as is: https://datatracker.ietf.org/doc/html/rfc4954#section-8 (seecontinue-req)Indeed, 334 expects optionally a
base64value butmailgunsend to us:334 Go ahead\r\n(and "Go ahead" is not a validbase64value). So ocaml-base64 raises an exceptionMalformed input(and, I believe that the stack trace disappear due tolwt).The solution is to be more resilient in
colombeand just ignore invalidbase64values. I will propose a patch oncolombe.jsthomas commentedon Jul 26, 2021
Thanks for taking a look, @dinosaure, I updated the version of
colombeon my system and can confirm that it's working for me now. It's too bad that mailgun doesn't respect RFC 4954, one would think they have plenty of engineering resources to be able to do that.I'm not sure if the convention is for the maintainer or the person who opened the issue to close, but as far as I'm concerned this can be closed now.
joseferben commentedon Jul 26, 2021
Thanks both!