Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
  • Loading branch information
miqdadyyy committed Jan 2, 2020
1 parent a7f5125 commit 41e7a79
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ SMTP_PORT=
SMTP_USERNAME=
SMTP_PASSWORD=
SENDER_EMAIL=
SENDER_NAME=
SENDER_NAME=
PORT=3000
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Mail Queue
### Description
Microservice to send email asyncrhonusly by sending `address`, `subject`, and `content`.
### Usage
#### Instalation :
- Clone this project
- Make sure your machine has Go with minimum version 1.13
- Run `go get` on this directory
- Run `go mod download` too
- Type `go run main.go`
#### Routes :
`/` (GET) : index
`/send` (POST) : sending email
#### Environment :
copy `.env.example` to `.env` and fill the requirements.
> - SMTP_HOST : host of your SMTP server
> - SMTP_PORT : port of your SMTP server
> - SMTP_USERNAME : username of your SMTP server
> - SMTP_PASSWORD : password of your SMTP server
> - SENDER_EMAIL : email of sender
> - PORT : port of this microservice
#### Example :
In this case i used GuzzleHttp on Laravel for example
```php
$g = new \GuzzleHttp\Client();
$addresses = ["[email protected]", "[email protected]"];
$content = new \App\Mail\InvoiceCreated(\App\Invoice::first());
$data = [
"addresses" => $addresses,
"email" => [
"subject" => "Testing World",
"content" => $content->render()
]
];
$g->postAsync("http://0.0.0.0:3000/send", [\GuzzleHttp\RequestOptions::JSON => $data])->wait();
```
Data :
```
[
"addresses" => $addresses,
"email" => [
"subject" => $subject
"content" => $content
]
]
]
```
`$addresses` : Array of target email
`$content` : Content of email (HTML format)
`$subject` : Subject email
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/subosito/gotenv"
"log"
"net/http"
"os"
)

func init() {
Expand All @@ -21,5 +22,5 @@ func main(){
router.HandleFunc("/send", controllers.SendMail).Methods("POST")

http.Handle("/", router)
log.Fatal(http.ListenAndServe(":3000", nil))
log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), nil))
}

0 comments on commit 41e7a79

Please sign in to comment.