Menu

Tree [095b5b] master /
 History

HTTPS access


File Date Author Commit
 Godeps 2016-10-02 adic adic [6a72f9] Add vendor dependencies
 example 2016-09-28 adic adic [f63b3a] Add testing
 example_service 2016-09-30 adic adic [da9951] Basic Service now runs wo TLS
 service 2016-10-13 Adrian Clepcea Adrian Clepcea [258995] Fix sending mail whit no auth and mail in json
 vendor 2016-10-02 adic adic [6a72f9] Add vendor dependencies
 .gitignore 2016-09-30 adic adic [da9951] Basic Service now runs wo TLS
 .travis.yml 2016-10-05 Adrian Clepcea Adrian Clepcea [8118e0] ÃAdd to travis
 LICENSE.md 2016-10-05 Adrian Clepcea Adrian Clepcea [c204cf] Add License
 README.md 2017-04-06 Adrian Clepcea Adrian Clepcea [095b5b] Update README.md
 config.json 2016-09-30 adic adic [da9951] Basic Service now runs wo TLS
 mailsender.go 2016-09-30 adic adic [da9951] Basic Service now runs wo TLS

Read Me

Build Status

Mailsender

Description

Simple library to send mails from go.
It is intended to ease the sending of mails by adding anothe rlayer on top of go smtp library.
You can use it to send mails through an unencrypted connection or through an encrypted connection.
It also provides the posibility to use a self signed certificate for the mail server.

You can send mails using one of the three methods:

  • SendMail - will allow you to send a mail using a connection without Tls security (unencrypted), but with authentication.
  • SendMailWithoutAth - will allow you to send a mail using a connection without Tls security and without authentication. This is a setup that you should not have available if you are using a public mail server.
  • SendMailTls - will allow you to send a mail using a secure connection (with Tls) and with authentication. This is the most secure option. Here you can have three variants:
  • Use a server that has a certificate signed by a known authority (this is the case for Google, Yahoo etc.). Before calling SendMailTls you will have to obtain the tls config using the CreateTlsConfig method
  • Use a server that has a self signed certificate or a certificate that is not known by your system. Before calling SendMailTls you will have to obtain the tls config using the CreateTlsConfigWithCA method. This method receives the name of the CA file that will be used to validate the server signature.
  • Use a server that provides a secure connection but you do not care to verify the connection (this means that you don't care for a MITM atack). In this case you should obtain the tls config using the CreateInsecureTlsConfig method.

Simple service implementation

In example_service folder you find a possible implementation for a service that will listen for a REST request that can send mails.
For example, you could have a config.json file near your executable that could have a content like:

```
{
"mailsetup":{
"server":"mail.yourmailserver.net:465",
"defaultmail":"admin@yourmailserver.net",
"defaultpassword":"verysecretpass",
"insecuretls":false,
"usetls":true,
"useauth":true
},
"servicesetup":{
"port":8080,
"certfile":"",
"keyfile":"",
"cafile": ""
}
}

This tells the program to use the ```mail.yourmailserver.net``` mail server, to connect to the port ```465```, to use the ```admin@yourmailserver.net``` as the default mail address for authentication, and the ```verysecretpass``` password. This configuration would use a secure connection to the mail server to send mails.

The service would listen for requests on port 8080.

A possible request to send a mail using the service running on the localhost and curl is:

curl -X POST http://localhost:8080/sendmail -d '{"To":{"Name":"","Address":"user@somemailserver.com"},"Subject":"test","Body":"From service"}'

This would send a mail comming from ```admin@yourmailserver.net``` with the subject and body specified in the curl request.

curl -X POST http://localhost:8080/sendmail -d '{"To":{"Name":"","Address":"user@somemailserver.com"},"Subject":"test","Body":"From service", "From":{"Name":"","Address":"user@yourmailserver.net"},"Password":"otherpass"}'
This would send a mail comming fromuser@yourmailserver.net``` with the subject and body specified in the curl request as long as the password of this user is valid for your mailserver.

To make the service use a secure connection (https), you should provide a key and a cert file.

To restrict access only to the clients with a valid certificate, use the corresponding CA file in the configuration file.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.