-
Notifications
You must be signed in to change notification settings - Fork 1
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
0ef12e7
commit 961ff13
Showing
18 changed files
with
380 additions
and
671 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,19 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
*.pb.go | ||
app.env | ||
examples/ |
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,24 @@ | ||
# Builder | ||
FROM golang:1.14.6-alpine3.12 as builder | ||
|
||
COPY . /app/ | ||
WORKDIR /app | ||
RUN go mod download | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -o ./ -a -installsuffix cgo /app/... | ||
|
||
|
||
# Runner | ||
FROM alpine:3.15.0 | ||
RUN apk add --no-cache ca-certificates && update-ca-certificates | ||
WORKDIR /app | ||
|
||
COPY --from=builder /app/email-microservice /app/email-microservice | ||
EXPOSE $PORT | ||
EXPOSE $PROMETHEUS_PORT | ||
|
||
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.6 && \ | ||
wget -O /bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ | ||
chmod +x /bin/grpc_health_probe | ||
|
||
CMD [ "./email-microservice" ] |
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,76 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/crossphoton/email-microservice/examples/src" | ||
) | ||
|
||
func sendRawEmail(req *src.RawSendEmailRequest) (*src.ResponseMessage, error) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
||
res, err := client.SendRawEmail(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
|
||
func RawEmail() (*src.ResponseMessage, error) { | ||
// Raw request | ||
rawEmailRequest := src.RawSendEmailRequest{ | ||
Recipients: []string{ | ||
"Aditya Agrawal<email@e.crossphoton.tech>", | ||
// "spam@e.crossphoton.tech", | ||
// "support@e.crossphoton.tech", | ||
}, | ||
Body: []byte(RawEmailBody), | ||
} | ||
return sendRawEmail(&rawEmailRequest) | ||
} | ||
|
||
const RawEmailBody = `From: "Sender Name" <sender@example.com> | ||
To: recipient@example.com | ||
Subject: Customer service contact info | ||
Content-Type: multipart/mixed; | ||
boundary="a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a" | ||
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a | ||
Content-Type: multipart/alternative; | ||
boundary="sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a" | ||
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a | ||
Content-Type: text/plain; charset=iso-8859-1 | ||
Content-Transfer-Encoding: quoted-printable | ||
Please see the attached file for a list of customers to contact. | ||
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a | ||
Content-Type: text/html; charset=iso-8859-1 | ||
Content-Transfer-Encoding: quoted-printable | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Hello!</h1> | ||
<p>Please see the attached file for a list of customers to contact.</p> | ||
</body> | ||
</html> | ||
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a-- | ||
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a | ||
Content-Type: text/plain; name="customers.txt" | ||
Content-Description: customers.txt | ||
Content-Disposition: attachment;filename="customers.txt"; | ||
creation-date="Sat, 05 Aug 2017 19:35:36 GMT"; | ||
Content-Transfer-Encoding: base64 | ||
SUQsRmlyc3ROYW1lLExhc3ROYW1lLENvdW50cnkKMzQ4LEpvaG4sU3RpbGVzLENhbmFkYQo5MjM4 | ||
OSxKaWUsTGl1LENoaW5hCjczNCxTaGlybGV5LFJvZHJpZ3VleixVbml0ZWQgU3RhdGVzCjI4OTMs | ||
QW5heWEsSXllbmdhcixJbmRpYQ== | ||
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a-- | ||
` |
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
"github.com/crossphoton/email-microservice/examples/src" | ||
) | ||
|
||
func sendEmailStd(req *src.SendEmailRequest) (*src.ResponseMessage, error) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
||
res, err := client.SendEmail(ctx, req) | ||
if err != nil { | ||
log.Fatalf("request failed: %v", err) | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func StdEmail() (*src.ResponseMessage, error) { | ||
emailRequest := src.SendEmailRequest{ | ||
Recipients: &src.Recipients{ | ||
To: []string{ | ||
"Aditya Agrawal<email@e.crossphoton.tech>", | ||
}, | ||
Cc: []string{ | ||
"Spam Address<spam@e.crossphoton.tech>", | ||
}, | ||
Bcc: []string{ | ||
"support@e.crossphoton.tech", | ||
}, | ||
}, | ||
Subject: "Hi there. I hope you're good", | ||
ContentType: "text/html", | ||
Body: "<h1>This is heading</h1><p>This is text</p>", | ||
} | ||
|
||
return sendEmailStd(&emailRequest) | ||
} |
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,42 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
"github.com/crossphoton/email-microservice/examples/src" | ||
) | ||
|
||
func sendEmailWithTemplate(req *src.SendEmailWithTemplateRequest) (*src.ResponseMessage, error) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
||
res, err := client.SendEmailWithTemplate(ctx, req) | ||
if err != nil { | ||
log.Fatalf("request failed: %v", err) | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func TemplateEmail() (*src.ResponseMessage, error) { | ||
// Template request | ||
emailRequest := src.SendEmailWithTemplateRequest{ | ||
Recipients: &src.Recipients{ | ||
To: []string{ | ||
"Aditya Agrawal<adiag1200@gmail.com>", | ||
}, | ||
}, | ||
TemplateName: "email-confirm", | ||
TemplateParams: map[string]string{ | ||
"UserName": "Aditya Agrawal", | ||
"ConfirmAccountLink": "https://google.com", | ||
"UnsubscribeLink": "https://google.com/unsubscribe", | ||
}, | ||
Subject: "This is from a template", | ||
} | ||
|
||
return sendEmailWithTemplate(&emailRequest) | ||
} |
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 @@ | ||
protoc --go_out=. --go-grpc_out=. --proto_path=.. email.proto |
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
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 |
---|---|---|
@@ -1,107 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/crossphoton/email-microservice/src" | ||
) | ||
|
||
func main() { | ||
// Template request | ||
templateRequest := src.SendEmailWithTemplateRequest{ | ||
Recipients: &src.Recipients{ | ||
To: []string{ | ||
"Aditya Agrawal<adiag1200@gmail.com>", | ||
}, | ||
}, | ||
TemplateName: "email-confirm", | ||
TemplateParams: map[string]string{ | ||
"UserName": "Aditya Agrawal", | ||
"ConfirmAccountLink": "https://google.com", | ||
"UnsubscribeLink": "https://google.com/unsubscribe", | ||
}, | ||
Subject: "This is from a template", | ||
} | ||
|
||
res, err := client.SendEmailWithTemplate(context.Background(), &templateRequest) | ||
res, err := TemplateEmail() | ||
if err != nil { | ||
log.Println("error: ", err) | ||
log.Printf("error: %v", err) | ||
} else { | ||
log.Print(res) | ||
} | ||
|
||
log.Print(res) | ||
|
||
// Raw request | ||
rawEmailRequest := src.RawSendEmailRequest{ | ||
Recipients: []string{ | ||
"Aditya Agrawal<email@e.crossphoton.tech>", | ||
"spam@e.crossphoton.tech", | ||
"support@e.crossphoton.tech", | ||
}, | ||
Body: []byte(RawEmailBody), | ||
// Raw email request | ||
res, err = RawEmail() | ||
if err != nil { | ||
log.Printf("error: %v", err) | ||
} else { | ||
log.Print(res) | ||
} | ||
sendRawEmail(&rawEmailRequest) | ||
|
||
// Standard email | ||
emailRequest := src.SendEmailRequest{ | ||
Recipients: &src.Recipients{ | ||
To: []string{ | ||
"Aditya Agrawal<email@e.crossphoton.tech>", | ||
}, | ||
Cc: []string{ | ||
"Spam Address<spam@e.crossphoton.tech>", | ||
}, | ||
Bcc: []string{ | ||
"support@e.crossphoton.tech", | ||
}, | ||
}, | ||
Subject: "Hi there. I hope you're good", | ||
ContentType: "text/html", | ||
Body: "<h1>This is heading</h1><p>This is text</p>", | ||
res, err = StdEmail() | ||
if err != nil { | ||
log.Printf("error: %v", err) | ||
} else { | ||
log.Print(res) | ||
} | ||
sendEmailStd(&emailRequest) | ||
} | ||
|
||
const RawEmailBody = `From: "Sender Name" <sender@example.com> | ||
To: recipient@example.com | ||
Subject: Customer service contact info | ||
Content-Type: multipart/mixed; | ||
boundary="a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a" | ||
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a | ||
Content-Type: multipart/alternative; | ||
boundary="sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a" | ||
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a | ||
Content-Type: text/plain; charset=iso-8859-1 | ||
Content-Transfer-Encoding: quoted-printable | ||
Please see the attached file for a list of customers to contact. | ||
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a | ||
Content-Type: text/html; charset=iso-8859-1 | ||
Content-Transfer-Encoding: quoted-printable | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Hello!</h1> | ||
<p>Please see the attached file for a list of customers to contact.</p> | ||
</body> | ||
</html> | ||
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a-- | ||
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a | ||
Content-Type: text/plain; name="customers.txt" | ||
Content-Description: customers.txt | ||
Content-Disposition: attachment;filename="customers.txt"; | ||
creation-date="Sat, 05 Aug 2017 19:35:36 GMT"; | ||
Content-Transfer-Encoding: base64 | ||
SUQsRmlyc3ROYW1lLExhc3ROYW1lLENvdW50cnkKMzQ4LEpvaG4sU3RpbGVzLENhbmFkYQo5MjM4 | ||
OSxKaWUsTGl1LENoaW5hCjczNCxTaGlybGV5LFJvZHJpZ3VleixVbml0ZWQgU3RhdGVzCjI4OTMs | ||
QW5heWEsSXllbmdhcixJbmRpYQ== | ||
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a-- | ||
` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
protoc --go_out=. --go-grpc_out=. email.proto | ||
protoc --go_out=. --go-grpc_out=. email.proto health.proto |
Oops, something went wrong.