connection and login ok

This commit is contained in:
Laurent Ulrich
2025-07-27 21:09:37 +02:00
parent 6feda8eec1
commit adfac31417
2 changed files with 29 additions and 3 deletions

View File

@@ -10,6 +10,8 @@ import (
type MailBox struct {
Server string
User string
Password string
Client *imapclient.Client
}
@@ -22,11 +24,21 @@ func (mb *MailBox) Connect() error {
WordDecoder: &mime.WordDecoder{CharsetReader: charset.Reader},
}
var err error
mb.Client, err = imapclient.DialStartTLS(mb.Server, options)
mb.Client, err = imapclient.DialTLS(mb.Server, options)
if err != nil {
log.Println("Error connnecting to", mb.Server, ":", err)
return err
}
log.Println("Connected")
err = mb.Client.Login(mb.User, mb.Password).Wait()
if err != nil {
log.Fatal("failed to login:", err)
}
log.Println("Logged in")
return nil
}
func (mb *MailBox) Close() {
mb.Client.Close()
}