flashmob / go-guerrilla

Mini SMTP server written in golang
MIT License
2.77k stars 365 forks source link

How to quick test by sending an email to go-guerilla server in localhost ? #213

Closed wahyudibo closed 4 years ago

wahyudibo commented 4 years ago

Thanks for the cool library. Pardon me if i ask dumb question or haven't read the documentation thoroughly or if this issued have been asked before. My question is simple: is there any simple way for us to send an email via localhost to go-guerilla server also started in same localhost ?

I want to add some custom backend to parse email body and want to test it in my local. I read function talkToServer in api_test.go and try to replicate it in my local but i haven't seen the email in MySQL database. So i guess the function is not really sending an email. Here are my code for starting the guerilla server :

package main

import (
    "fmt"
    "log"
    "os"
    "os/signal"
    "syscall"

    "github.com/flashmob/go-guerrilla"
    "github.com/flashmob/go-guerrilla/backends"
    _ "github.com/go-sql-driver/mysql"
)

func main() {
    done := make(chan os.Signal, 1)
    signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

    cfg := &guerrilla.AppConfig{
        BackendConfig: backends.BackendConfig{
            "save_workers_size":  3,
            "save_process":       "HeadersParser|Debugger|Hasher|Header|Compressor|Sql",
            "sql_driver":         "mysql",
            "sql_dsn":            "root:mariadbadmin@tcp(127.0.0.1:3306)/goguerilla?readTimeout=10s&writeTimeout=10s",
            "mail_table":         "new",
            "log_received_mails": true,
            "primary_mail_host":  "example.com",
        },
    }

    d := guerrilla.Daemon{Config: cfg}
    err := d.Start()

    if err == nil {
        fmt.Println("Server Started!")
    }

    <-done
    log.Print("Server stopped")
}

Thanks in advance !

lllama commented 4 years ago

I use Swaks for testing: https://github.com/jetmore/swaks

There’s a good chance it’ll be available via your package manager.