-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95d8920
commit bfff024
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Using of this example | ||
===================== | ||
|
||
Run the create_certs.bash to generate certificates for server and client | ||
|
||
./create_certs.bash | ||
|
||
Edit the data/server.json according to your settings | ||
|
||
Start the container of restgomail | ||
|
||
docker-compose up -d | ||
|
||
Now you can send messages to the container with the php sample | ||
|
||
php ./send_sample_request.php | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# Generate certificates for server and client | ||
|
||
SERVERCERTNAME="restgomail" | ||
CLIENTCERTNAME="rgmclient" | ||
|
||
openssl genrsa -out ${SERVERCERTNAME}.key 2048 | ||
openssl ecparam -genkey -name secp384r1 -out ${SERVERCERTNAME}.key | ||
openssl req -new -x509 -sha256 -key ${SERVERCERTNAME}.key -out ${SERVERCERTNAME}.crt -days 365 | ||
|
||
openssl genrsa -out ${CLIENTCERTNAME}.key 2048 | ||
openssl ecparam -genkey -name secp384r1 -out ${CLIENTCERTNAME}.key | ||
openssl req -new -x509 -sha256 -key ${CLIENTCERTNAME}.key -out ${CLIENTCERTNAME}.crt -days 365 | ||
|
||
mv ${SERVERCERTNAME}.key ./data/ | ||
mv ${SERVERCERTNAME}.crt ./data/ | ||
|
||
cp ${CLIENTCERTNAME}.crt ./data/${CLIENTCERTNAME}.crt |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"restgomail": { | ||
"smtpHost": "smtp.gmail.com", | ||
"smtpPort": "587", | ||
"smtpAuthRequired": true, | ||
"smtpAuthPassword": "gmailpasswordsample", | ||
"smtpAllowedFromAddressOnly": "sampleuser@gmail.com", | ||
"httpsListenPort": "44325", | ||
"tlsKeyFile": "restgomail.key", | ||
"tlsCertFile": "restgomail.crt", | ||
"allowOnlyKnownCertificates": true, | ||
"knownCertificates": { | ||
"civisdbContainer": "@rgmclient.crt" | ||
}, | ||
"waitSecondsAfterSmtpreq": 10 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
restgomail: | ||
image: hyperprog/restgomail | ||
container_name: restgomail | ||
ports: | ||
- "44325:44325" | ||
volumes: | ||
- ./data:/restgomail |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
$json = | ||
'{ | ||
"sendmail": { | ||
"from": "sampleuser@gmail.com", | ||
"to": "target.address@mailbox.com", | ||
"subject": "Test from PHP", | ||
"bodyhtml": "This is received through <h1>RestGoMail</h1>" | ||
} | ||
}'; | ||
|
||
$r = SendHttpPostWithCert("https://127.0.0.1:44325/sendmail",$json,"rgmclient.crt","rgmclient.key"); | ||
print("Received:".$r); | ||
|
||
function SendHttpPostWithCert($url, $postdata, $certfile, $keyfile) | ||
{ | ||
$curl = curl_init(); | ||
|
||
curl_setopt($curl, CURLOPT_POST, 1); | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); | ||
|
||
curl_setopt($curl, CURLOPT_SSLKEY, $keyfile); | ||
curl_setopt($curl, CURLOPT_SSLCERT, $certfile); | ||
|
||
curl_setopt($curl, CURLOPT_CERTINFO, true); | ||
|
||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); | ||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); | ||
|
||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); | ||
curl_setopt($curl, CURLOPT_TIMEOUT, 60); | ||
|
||
curl_setopt($curl, CURLOPT_URL, $url); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
$result = curl_exec($curl); | ||
$info = curl_getinfo($curl,CURLINFO_CERTINFO); | ||
|
||
print "You can check this certificate:" | ||
print "\n=============================\n"; | ||
$c = $info[0]['Cert']; | ||
$c = preg_replace('/\-+BEGIN CERTIFICATE\-+/','',$c); | ||
$c = preg_replace('/\-+END CERTIFICATE\-+/','',$c); | ||
$c = trim($c); | ||
print $c; | ||
print "\n=============================\n"; | ||
|
||
curl_close($curl); | ||
|
||
return $result; | ||
} | ||
|