After setting up system like https://askubuntu.com/a/643990/829858 , I am able to send mail via mailx, but how can I send mail via golang using this system . I don't want to call cmd module to call mailx.
Asked
Active
Viewed 213 times
0
-
There are plenty of golang packages to send mail. Make your pick and use one of them. For instance github.com/go-gomail/gomail. You can also use the standard package library, but it is less convenient when adding attachment or using mime. See [here](https://blog.mailtrap.io/golang-send-email/) for a short tutorial. – chmike Feb 11 '20 at 11:58
-
tutorial and package which you provided requires smtp server and connect to server itself, while I want it to deliver mail to local ssmtp which will connect to smtp server – dgfjxcv Feb 11 '20 at 12:08
-
I never used ssmtp. I use postfix configured as a satellite setup. It listen to port 25 but accept only connexions from localhost. You can then use the above packages by providing the address localhost:25. I couldn't find out how to communicate with ssmtp. All the examples I have seen use shell commands. I'm afraid you are stuck to use system commands to use ssmtp. – chmike Feb 11 '20 at 12:22
-
I don't want to tell smtp server to script rather let it deliver to ssmtp, If mailx can mimic it why not code in golang , there must be some way or protocol which need to be implemented , any help in that direction – dgfjxcv Feb 11 '20 at 12:25
-
It looks like mailx and the like delegate mail sending to the sendmail program which uses the ssmtp configuration files. So to send a mail with ssmtp, it seam that you have to exec the sendmail command with the appropriate parameters. I would suggest to use Postfix instead of ssmtp. – chmike Feb 11 '20 at 12:37
-
using exec commands I am able to send , but if there is a way I want to mimic it in whole golang code – dgfjxcv Feb 11 '20 at 12:42
-
As I understand it, you can’t because it’s sendmail that connects to the remote server and execute the communication protocol. If you want to implement something in Go you would have to either use sendmail or reimplement sendmail in Go. – chmike Feb 11 '20 at 14:01