Skip to content

Commit

Permalink
almost final
Browse files Browse the repository at this point in the history
  • Loading branch information
crossphoton authored Dec 2, 2021
1 parent 0ef12e7 commit 961ff13
Show file tree
Hide file tree
Showing 18 changed files with 380 additions and 671 deletions.
19 changes: 19 additions & 0 deletions .dockerignore
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/
24 changes: 24 additions & 0 deletions Dockerfile
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" ]
76 changes: 76 additions & 0 deletions examples/Raw.go
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--
`
43 changes: 43 additions & 0 deletions examples/Std.go
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)
}
42 changes: 42 additions & 0 deletions examples/Template.go
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)
}
1 change: 1 addition & 0 deletions examples/gen_proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
protoc --go_out=. --go-grpc_out=. --proto_path=.. email.proto
2 changes: 1 addition & 1 deletion examples/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/crossphoton/email-microservice/src"
"github.com/crossphoton/email-microservice/examples/src"
"google.golang.org/grpc"
)

Expand Down
104 changes: 15 additions & 89 deletions examples/main.go
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--
`
22 changes: 0 additions & 22 deletions examples/raw.go

This file was deleted.

23 changes: 0 additions & 23 deletions examples/std.go

This file was deleted.

2 changes: 1 addition & 1 deletion gen_proto.sh
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
Loading

0 comments on commit 961ff13

Please sign in to comment.