-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into pr-deploy-workflow-patch
- Loading branch information
Showing
14 changed files
with
80 additions
and
47 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
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
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
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,6 +1,7 @@ | ||
package send | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"net/smtp" | ||
"strings" | ||
|
@@ -111,20 +112,73 @@ func (e *EmailRequest) sendEmailViaSMTP() error { | |
|
||
sender := mailConfig.Username | ||
subject := e.Subject | ||
From := "[email protected]" | ||
recipients := e.To | ||
mime := "\nMIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n" | ||
body := []byte(subject + mime + e.Body) | ||
body := []byte(fmt.Sprintf("From: %s\r\nTo: %s\r\n%s%s%s", From, recipients[0], subject, mime, e.Body)) | ||
|
||
err := smtp.SendMail( | ||
conn, err := tls.Dial( | ||
"tcp", | ||
mailConfig.Server+":"+mailConfig.Port, | ||
auth, | ||
sender, | ||
recipients, | ||
body, | ||
) | ||
&tls.Config{ | ||
InsecureSkipVerify: false, | ||
ServerName: mailConfig.Server, | ||
}) | ||
|
||
if err != nil { | ||
|
||
return fmt.Errorf("failed to connect to the server: %v", err) | ||
|
||
} | ||
|
||
defer conn.Close() | ||
|
||
client, err := smtp.NewClient(conn, mailConfig.Server) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error connecting to SMTP server: %w", err) | ||
|
||
return fmt.Errorf("failed to create SMTP client: %v", err) | ||
|
||
} | ||
|
||
defer client.Quit() | ||
|
||
if err = client.Auth(auth); err != nil { | ||
return fmt.Errorf("failed to authenticate: %v", err) | ||
|
||
} | ||
|
||
if err = client.Mail(sender); err != nil { | ||
return fmt.Errorf("failed to set the sender: %v", err) | ||
|
||
} | ||
|
||
if err = client.Rcpt(recipients[0]); err != nil { | ||
return fmt.Errorf("failed to set the recipient: %v", err) | ||
|
||
} | ||
|
||
writer, err := client.Data() | ||
if err != nil { | ||
|
||
return fmt.Errorf("failed to write the message: %v", err) | ||
|
||
} | ||
|
||
_, err = writer.Write(body) | ||
if err != nil { | ||
|
||
return fmt.Errorf("failed to send the message: %v", err) | ||
|
||
} | ||
|
||
err = writer.Close() | ||
if err != nil { | ||
|
||
return fmt.Errorf("failed to close the writer: %v", err) | ||
|
||
} | ||
|
||
return nil | ||
|
||
} |
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 |
---|---|---|
|
@@ -54,7 +54,6 @@ func TestAddToContactUs(t *testing.T) { | |
contactData := models.ContactUs{ | ||
Name: "John Doe", | ||
Email: "[email protected]", | ||
Subject: "</br><i>Inquiry about services3 with html", | ||
Message: "I would like to know more about your services3.", | ||
} | ||
payload, _ := json.Marshal(contactData) | ||
|
@@ -115,7 +114,6 @@ func TestAddToContactUs(t *testing.T) { | |
contactData := models.ContactUs{ | ||
Name: "John Doe", | ||
Email: "invalid_email", | ||
Subject: "test subject", | ||
Message: "message test", | ||
} | ||
payload, _ := json.Marshal(contactData) | ||
|
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 |
---|---|---|
|
@@ -40,7 +40,6 @@ func TestDeleteContactUs(t *testing.T) { | |
contact := models.ContactUs{ | ||
ID: utility.GenerateUUID(), | ||
Email: fmt.Sprintf("contact%[email protected]", currUUID), | ||
Subject: fmt.Sprintf("Test subject - %v ", currUUID), | ||
Message: fmt.Sprintf("Test message - %v ", currUUID), | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -40,13 +40,11 @@ func TestGetAllContactUs(t *testing.T) { | |
contact1 := models.ContactUs{ | ||
ID: utility.GenerateUUID(), | ||
Email: fmt.Sprintf("contact%[email protected]", currUUID), | ||
Subject: fmt.Sprintf("First subject - %v ", currUUID), | ||
Message: fmt.Sprintf("First test message - %v ", currUUID), | ||
} | ||
contact2 := models.ContactUs{ | ||
ID: utility.GenerateUUID(), | ||
Email: fmt.Sprintf("contact2%[email protected]", currUUID), | ||
Subject: fmt.Sprintf("Second subject - %v ", currUUID), | ||
Message: fmt.Sprintf("Second test message - %v ", currUUID), | ||
} | ||
|
||
|
@@ -149,7 +147,6 @@ func TestGetContactUsById(t *testing.T) { | |
contact := models.ContactUs{ | ||
ID: utility.GenerateUUID(), | ||
Email: fmt.Sprintf("contact%[email protected]", currUUID), | ||
Subject: fmt.Sprintf("Test subject - %v ", currUUID), | ||
Message: fmt.Sprintf("Test message - %v ", currUUID), | ||
} | ||
|
||
|
@@ -251,7 +248,6 @@ func TestGetContactUsByEmail(t *testing.T) { | |
contact := models.ContactUs{ | ||
ID: utility.GenerateUUID(), | ||
Email: fmt.Sprintf("contact%[email protected]", currUUID), | ||
Subject: fmt.Sprintf("Test subject - %v ", currUUID), | ||
Message: fmt.Sprintf("Test message - %v ", currUUID), | ||
} | ||
|
||
|
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
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