Created
June 7, 2018 08:24
-
-
Save gravataLonga/2f4c82832d32461dd42104e17543561f to your computer and use it in GitHub Desktop.
SMTP Testing Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"fmt" | |
"net/smtp" | |
"bufio" | |
"os" | |
"strings" | |
) | |
func main() { | |
reader := bufio.NewReader(os.Stdin) | |
fmt.Print("From: ") | |
from, _ := reader.ReadString('\n') | |
fmt.Print("To: ") | |
to, _ := reader.ReadString('\n') | |
fmt.Print("SMTP: ") | |
smt, _ := reader.ReadString('\n') | |
fmt.Print("Port: ") | |
port, _ := reader.ReadString('\n') | |
fmt.Print("Pass: ") | |
pass, _ := reader.ReadString('\n') | |
fmt.Print("Subject: ") | |
subject, _ := reader.ReadString('\n') | |
fmt.Print("Body: ") | |
body, _ := reader.ReadString('\n') | |
send(strings.TrimSpace(from), strings.TrimSpace(to), strings.TrimSpace(subject), strings.TrimSpace(body), strings.TrimSpace(smt), strings.TrimSpace(port), strings.TrimSpace(pass)) | |
} | |
func send(from, to, subject, body, smt, port, pass string) { | |
msg := "From: " + from + "\n" + | |
"To: " + to + "\n" + | |
"Subject: " + subject + "\n\n" + | |
body | |
log.Printf("From: %s", from) | |
log.Printf("To: %s", to) | |
log.Printf("Subject: %s", subject) | |
log.Printf("Body: %s", body) | |
log.Printf("Smtp: %s", smt) | |
log.Printf("Port: %s", port) | |
log.Printf("Pass: %s", pass) | |
err := smtp.SendMail(smt + ":" + port, | |
smtp.PlainAuth("", from, pass, smt), | |
from, []string{to}, []byte(msg)) | |
if err != nil { | |
log.Printf("smtp error: %s", err) | |
return | |
} | |
log.Print("sent") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment