Created
October 21, 2015 10:10
-
-
Save alok87/56aaecb6c2e102bcf625 to your computer and use it in GitHub Desktop.
Sendmail Using Golang without SMTP- Example
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 ( | |
"io/ioutil" | |
"os/exec" | |
"fmt" | |
) | |
// EXAMPLE: echo "Subject: TestnHello" | sendmail -f [email protected] [email protected] | |
// Useful Links: https://gobyexample.com/spawning-processes | |
func main() { | |
fromEmail := "[email protected]" | |
toEmail := "[email protected]" | |
msg := "Subject: Sendmail Using Go" | |
sendmail := exec.Command("/usr/sbin/sendmail", "-f", fromEmail, toEmail) | |
stdin, err := sendmail.StdinPipe() | |
if err != nil { | |
panic(err) | |
} | |
stdout, err := sendmail.StdoutPipe() | |
if err != nil { | |
panic(err) | |
} | |
sendmail.Start() | |
stdin.Write([]byte(msg)) | |
stdin.Close() | |
sentBytes, _ := ioutil.ReadAll(stdout) | |
sendmail.Wait() | |
fmt.Println("Send Command Output\n") | |
fmt.Println(string(sentBytes)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment