Skip to content

Instantly share code, notes, and snippets.

@auycro
Last active August 29, 2015 14:02
Show Gist options
  • Save auycro/9011a4c609ea77271541 to your computer and use it in GitHub Desktop.
Save auycro/9011a4c609ea77271541 to your computer and use it in GitHub Desktop.
Sending Email via CMD ref. https://github.com/jimlawless/gsend/
// 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 to@some.place -f you@gmail.com -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