Last active
September 10, 2021 03:35
-
-
Save winston-wen/1d7f1941ab564c19ba757d2661b0c417 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
| "net/smtp" | |
| "log" | |
| "os/exec" | |
| "fmt" | |
| ) | |
| func main() { | |
| // Set up authentication information. | |
| user := "[email protected]" | |
| pswd := "blabla.password" | |
| server := "mail.ustc.edu.cn" | |
| wlt_host := "202.38.64.59" | |
| auth := smtp.PlainAuth("", user, pswd, server) | |
| // Connect to the server, authenticate, set the sender and recipient, | |
| // and send the email all in one step. | |
| hostname, err := exec.Command("hostname").Output() | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| ip, err := exec.Command("/bin/ip", "route", "get", wlt_host).Output() | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| msg := fmt.Sprintf("Subject: Labrador from %s\nTo: %s\n\n %s", hostname, user, ip) | |
| dest := fmt.Sprintf("%s:%d", server, 25) | |
| err = smtp.SendMail(dest, auth, user, []string{user}, []byte(msg)) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create
/etc/systemd/system/labrador.serviceThen execute
systemctl enable labrador.