Last active
August 29, 2015 14:02
-
-
Save auycro/9011a4c609ea77271541 to your computer and use it in GitHub Desktop.
Sending Email via CMD ref. https://github.com/jimlawless/gsend/
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
// Copyright 2013 - by Jim Lawless | |
// License: MIT / X11 | |
// See: http://www.mailsend-online.com/license2013.php | |
// | |
// Bear with me ... I'm a Go noob. | |
package main | |
import ( | |
"log" | |
"flag" | |
"net/smtp" | |
"fmt" | |
) | |
func main() { | |
to := flag.String("t","","destination Internet mail address") | |
from := flag.String("f","","the sender's GMail address") | |
pwd := flag.String("p","","the sender's password") | |
subject := flag.String("s","","subject line of email") | |
msg := flag.String("m","","a one-line email message") | |
flag.Usage=func() { | |
fmt.Printf("Syntax:\n\tGSend [flags]\nwhere flags are:\n") | |
flag.PrintDefaults() | |
} | |
fmt.Printf("GSend v 1.01 by Jim Lawless\n") | |
flag.Parse() | |
if flag.NFlag() != 5 { | |
flag.Usage() | |
return | |
} | |
body := "To: " + *to + "\r\nSubject: " + | |
*subject + "\r\n\r\n" + *msg | |
auth := smtp.PlainAuth("",*from,*pwd,"smtp.gmail.com") | |
err := smtp.SendMail("smtp.gmail.com:587",auth,*from, | |
[]string{*to},[]byte(body)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
//gsend -t [email protected] -f [email protected] -p yourpassword -s "Testing!" -m "This is a test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment