10000 Unable to Configure Email Sending Without `WithSSLPort` Using YAML Configuration · Issue #427 · uptrace/uptrace · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Unable to Configure Email Sending Without WithSSLPort Using YAML Configuration #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
doudyy opened this issue Oct 8, 2024 · 0 comments

Comments

@doudyy
Copy link
doudyy commented Oct 8, 2024

I'm having trouble configuring the email sending functionality in Uptrace (from docker) following the documentation at Sending Emails and based on the guidance in Issue #379.

I've written a working Go sample using the go-mail package that successfully sends an email through Gmail. The key to getting it working is not using the mail.WithSSLPort option. Here’s the relevant code that works for my setup:

package main                                                                                                                                                                                                                                                                                                       

import (
        "fmt"
        "log"

        mail "github.com/wneessen/go-mail"
)

func main() {
        from := "example@gmail.com"
        options := []mail.Option{
                mail.WithSMTPAuth("PLAIN"),
                mail.WithUsername("example@gmail.com"),
                mail.WithPassword("password_example"),
                mail.WithTLSPortPolicy(mail.TLSMandatory),
                // mail.WithSSLPort(false), // Error: dial failed: tls: first record does not look like a TLS handshake
                // mail.WithSSLPort(true), // Error: dial failed: tls: first record does not look like a TLS handshake
                // <no WithSSLPort>, // Success
                mail.WithPort(587),
        }

        // Create a new mailer instance
        client, err := mail.NewClient("smtp.gmail.com", options...)
        if err != nil {
                fmt.Println(err)
                return
        }

        // Create a new message
        msg := mail.NewMsg()
        msg.Subject("test")
        msg.SetBodyString(mail.TypeTextHTML, "test")
        if err := msg.FromFormat(from, from); err != nil {
                fmt.Println(err)
                return
        }
        if err := msg.To(from); err != nil {
                fmt.Println(err)
                return
        }

        // Send the email
        if err := client.DialAndSend(msg); err != nil {
                log.Fatal(err)
        }

        log.Println("Email sent successfully!")
}

The key point is that the email is sent only when mail.WithSSLPort is not called. However, I can't figure out how to replicate this behavior using the YAML configuration in Uptrace.

The current Go code in pkg/bunapp/app.go always calls mail.WithSSLPort due to the switch logic, making it difficult to bypass this option. Here is the relevant code:

options := []mail.Option{
    mail.WithSMTPAuth(cfg.AuthType),
    mail.WithUsername(cfg.Username),
    mail.WithPassword(cfg.Password),
}

switch {
case cfg.TLS == nil:
    options = append(options,
        mail.WithTLSPortPolicy(mail.TLSOpportunistic),
        mail.WithSSLPort(false), // Always called
        mail.WithPort(cfg.Port),
    )
case cfg.TLS.Disabled:
    options = append(options,
        mail.WithTLSPortPolicy(mail.NoTLS),
        mail.WithPort(cfg.Port),
    )
default:
    options = append(options,
        mail.WithTLSPortPolicy(mail.TLSMandatory),
        mail.WithSSLPort(false), // Always called
        mail.WithPort(cfg.Port),
    )

    tlsCfg, err := cfg.TLS.TLSConfig()
    if err != nil {
        return nil, err
    }
    options = append(options, mail.WithTLSConfig(tlsCfg))
}

My question is: how can I configure the YAML to avoid using mail.WithSSLPort and successfully send emails, just like in the working Go sample?

Any guidance on how to bypass or modify the switch logic in app.go or structure the configuration to disable WithSSLPort would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0