-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
37 lines (30 loc) · 960 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package geemail
import (
"bytes"
"encoding/json"
"net/http"
"time"
)
type Email struct {
ID int `json:"id"`
Sender string `json:"sender"`
Receiver string `json:"receiver"`
Subject string `json:"subject"`
Body []byte `json:"body"`
Time int64 `json:"time"`
}
func SendEmail(sender, receiver, subject string, body []byte, time int64) error {
email := Email{0, sender, receiver, subject, body, time}
reqBody, err := json.Marshal(email)
if err != nil {
return err
}
_, err = http.Post("https://geemail-backend.corp.geegle.org/api/addmail", "application/json", bytes.NewBuffer(reqBody))
return err
}
func SendEmailWithDelay(sender, receiver, subject string, body []byte, delay int64) error {
return SendEmail(sender, receiver, subject, body, time.Now().UnixNano()/1000000+delay)
}
func SendEmailNow(sender, receiver, subject string, body []byte) error {
return SendEmailWithDelay(sender, receiver, subject, body, 0)
}