Closed 3mb3dw0rk5 closed 3 years ago
I've just tried with a fresh example and it's working fine for me. What's the raw message being submitted?
I face this issue with this little example:
go.mod
:
module github.com/3mb3dw0rk5/gosmtpd
go 1.16
require github.com/mhale/smtpd v0.0.0-20210209185612-36ee4150ae3b // indirect
main.go
:
package main
import (
"bytes"
"log"
"net"
"net/mail"
"github.com/mhale/smtpd"
)
func mailHandler(origin net.Addr, from string, to []string, data []byte) error {
_, err := mail.ReadMessage(bytes.NewReader(data))
if err != nil {
log.Print(err)
log.Printf("\ndata: \"%s\"", data)
}
return nil
}
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Printf("Starting daemon")
srv := &smtpd.Server{
Addr: "0.0.0.0:8025",
Handler: mailHandler,
Hostname: "",
AuthRequired: true}
srv.ListenAndServe()
}
Python client sending a message:
client.py
:
import smtplib
from email.message import EmailMessage
smtp_client = smtplib.SMTP(host="localhost", port=8025)
smtp_client.ehlo()
sender_email = "senderemail@example.com"
receiver_email = "receiveremail@example.com"
msg = "Hello from python!"
smtp_client.sendmail(sender_email, receiver_email, msg)
smtp_client.close()
Output when starting the daemon and running the client script:
2021/03/07 08:55:20 main.go:23: Starting daemon
2021/03/07 08:55:22 main.go:15: malformed MIME header: missing colon: "Hello from python!"
2021/03/07 08:55:22 main.go:16:
data: "Received: from localhost.localdomain (localhost.localdomain. [::1])
by notebook (smtpd) with SMTP
for <receiveremail@example.com>; Sun, 7 Mar 2021 08:55:22 +0100 (CET)
Hello from python!
"
Looked into it again and it seems that the python example from doc is not complete. Passing a complete RFC822 content and the smtpd output is as expected.
Can be closed.
Hi,
I tried to use your simple example in
readme.md
But callingmail.ReadMessage
actually raises an errormalformed MIME header: missing colon: "..."
It seems that the
mail
package is not able to parse theRFC 2821 Received header
properly. Any idea how to fix this?