框架学习

golang发送邮件

package main

import (
    "net/smtp"
    "log"
)

func main() {
    from := "your.email@example.com"
    password := "your_password"
    to := "recipient.email@example.com"
    subject := "Subject of your email"
    body := "Body of your email"

    msg := "From: " + from + "\n" +
        "To: " + to + "\n" +
        "Subject: " + subject + "\n\n" +
        body

    err := smtp.SendMail("smtp.yourmailserver.com:587",
        smtp.PlainAuth("", from, password, "smtp.yourmailserver.com"),
        from, []string{to}, []byte(msg))

    if err != nil {
        log.Fatal(err)
    }

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