Skip to content

feat: [#633] Allow setting custom headers when sending mail#964

Merged
hwbrzzl merged 4 commits intogoravel:masterfrom
vendion:master
Mar 24, 2025
Merged

feat: [#633] Allow setting custom headers when sending mail#964
hwbrzzl merged 4 commits intogoravel:masterfrom
vendion:master

Conversation

@vendion
Copy link
Contributor

@vendion vendion commented Mar 19, 2025

This adds the ability to add custom headers to mails. This is done by adding new Mail.Headers() and Mailable.Headers() methods.

📑 Description

Closes goravel/goravel#633

The summary will be generated by Copilot in the below.

✅ Checks

  • Added test cases for my code

@vendion
Copy link
Contributor Author

vendion commented Mar 19, 2025

Could someone please check to see if I'm heading in the right direction before I finish up fixing the test files?

@codecov
Copy link

codecov bot commented Mar 19, 2025

Codecov Report

Attention: Patch coverage is 17.85714% with 23 lines in your changes missing coverage. Please review.

Project coverage is 69.21%. Comparing base (9c3ffb9) to head (8256974).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
mail/application.go 0.00% 14 Missing ⚠️
mail/job.go 0.00% 7 Missing ⚠️
mail/options.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #964      +/-   ##
==========================================
- Coverage   69.31%   69.21%   -0.11%     
==========================================
  Files         160      160              
  Lines       10713    10736      +23     
==========================================
+ Hits         7426     7431       +5     
- Misses       2951     2969      +18     
  Partials      336      336              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Mar 20, 2025

Thanks, checking.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Mar 20, 2025

@vendion Thanks, great PR 👍 It's good to go.

This adds the ability to add custom headers to mails. This is done by by
adding new `Mail.Headers()` and `Mailable.Headers()` methods.

Implements: goravel/goravel#633
Signed-off-by: Adam Jimerson <vendion@gmail.com>
Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM. Could you add a testing screenshot for this feature? To confirm if the code is expected.

@vendion
Copy link
Contributor Author

vendion commented Mar 21, 2025

Are you wanting a screenshot showing the custom headers in the email? If so, I can't get it to send an actual email via go test. The tests all say they pass, but my STMP server doesn't get anything.

vendion on vili framework on  master via 🐹 v1.24.1 took 0s
➜ go test -v github.com/goravel/framework/mail
=== RUN   TestApplicationTestSuite
  ERROR   No mail tests run, need create .env based on .env.example, then initialize it
--- PASS: TestApplicationTestSuite (0.00s)
=== RUN   TestEmailText
--- PASS: TestEmailText (0.00s)
=== RUN   TestEmailWithHTMLAttachments
--- PASS: TestEmailWithHTMLAttachments (0.00s)
=== RUN   TestEmailWithHTMLAttachmentsHTMLOnly
--- PASS: TestEmailWithHTMLAttachmentsHTMLOnly (0.00s)
=== RUN   TestEmailHTML
--- PASS: TestEmailHTML (0.00s)
=== RUN   TestEmailTextAttachment
--- PASS: TestEmailTextAttachment (0.00s)
=== RUN   TestEmailTextHtmlAttachment
--- PASS: TestEmailTextHtmlAttachment (0.00s)
=== RUN   TestEmailAttachment
--- PASS: TestEmailAttachment (0.00s)
=== RUN   TestHeaderEncoding
--- PASS: TestHeaderEncoding (0.00s)
=== RUN   TestEmailFromReader
--- PASS: TestEmailFromReader (0.00s)
=== RUN   TestNonAsciiEmailFromReader
--- PASS: TestNonAsciiEmailFromReader (0.00s)
=== RUN   TestNonMultipartEmailFromReader
--- PASS: TestNonMultipartEmailFromReader (0.00s)
=== RUN   TestBase64EmailFromReader
--- PASS: TestBase64EmailFromReader (0.00s)
=== RUN   TestAttachmentEmailFromReader
--- PASS: TestAttachmentEmailFromReader (0.00s)
=== RUN   Test_base64Wrap
--- PASS: Test_base64Wrap (0.00s)
=== RUN   Test_quotedPrintEncode
--- PASS: Test_quotedPrintEncode (0.00s)
=== RUN   TestMultipartNoContentType
--- PASS: TestMultipartNoContentType (0.00s)
=== RUN   TestNoMultipartHTMLContentTypeBase64Encoding
--- PASS: TestNoMultipartHTMLContentTypeBase64Encoding (0.00s)
=== RUN   Test_quotedPrintDecode
--- PASS: Test_quotedPrintDecode (0.00s)
=== RUN   TestParseSender
--- PASS: TestParseSender (0.00s)
PASS
ok  	github.com/goravel/framework/mail	(cached)
vendion on vili framework on  master via 🐹 v1.24.1 took 0s
➜ \cat .env
APP_KEY=
MAIL_HOST=127.0.0.1
MAIL_PORT=1024
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_FROM_ADDRESS=vendion@gmail.com
MAIL_FROM_NAME=vendion
MAIL_TO=vendion@gmail.com
MAIL_CC=
MAIL_BCC=
AWS_ACCESS_KEY_ID=
AWS_ACCESS_KEY_SECRET=
AWS_DEFAULT_REGION=
AWS_BUCKET=
AWS_URL=
ALIYUN_ACCESS_KEY_ID=
ALIYUN_ACCESS_KEY_SECRET=
ALIYUN_BUCKET=
ALIYUN_URL=
ALIYUN_ENDPOINT=
TENCENT_ACCESS_KEY_ID=
TENCENT_ACCESS_KEY_SECRET=
TENCENT_BUCKET=
TENCENT_URL=
MINIO_ACCESS_KEY_ID=
MINIO_ACCESS_KEY_SECRET=
MINIO_BUCKET=

Because this is based off master, there are some breaking changes that make swapping my current project over to my fork a pain.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Mar 21, 2025

@vendion You can run go test like this: MAIL_HOST= MAIL_PORT= MAIL_USERNAME= MAIL_PASSWORD= MAIL_FROM_ADDRESS= MAIL_FROM_NAME= MAIL_TO= go test ./mail/...

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Mar 21, 2025

And please run go run github.com/vektra/mockery/v2 locally to update the mock file.

@hwbrzzl hwbrzzl changed the title feat: Allow setting custom headers when sending mail feat: [#633] Allow setting custom headers when sending mail Mar 21, 2025
@vendion
Copy link
Contributor Author

vendion commented Mar 22, 2025

MAIL_HOST= MAIL_PORT= MAIL_USERNAME= MAIL_PASSWORD= MAIL_FROM_ADDRESS= MAIL_FROM_NAME= MAIL_TO= go test ./mail/...

Even running like that allows all tests to pass, but I'm not seeing an email. I'm using https://github.com/mailhog/MailHog as my SMTP for testing.

vendion on vili framework on  master [!] via 🐹 v1.24.1 took 0s
➜ MAIL_HOST=127.0.0.1 MAIL_PORT=1025 MAIL_USERNAME= MAIL_PASSWORD= MAIL_FROM_ADDRESS=vendion@gmail.com MAIL_FROM_NAME=vendion MAIL_TO=vendion@gmail.com go test -v ./mail/...
=== RUN   TestApplicationTestSuite
--- PASS: TestApplicationTestSuite (0.00s)
=== RUN   TestEmailText
--- PASS: TestEmailText (0.00s)
=== RUN   TestEmailWithHTMLAttachments
--- PASS: TestEmailWithHTMLAttachments (0.00s)
=== RUN   TestEmailWithHTMLAttachmentsHTMLOnly
--- PASS: TestEmailWithHTMLAttachmentsHTMLOnly (0.00s)
=== RUN   TestEmailHTML
--- PASS: TestEmailHTML (0.00s)
=== RUN   TestEmailTextAttachment
--- PASS: TestEmailTextAttachment (0.00s)
=== RUN   TestEmailTextHtmlAttachment
--- PASS: TestEmailTextHtmlAttachment (0.00s)
=== RUN   TestEmailAttachment
--- PASS: TestEmailAttachment (0.00s)
=== RUN   TestHeaderEncoding
--- PASS: TestHeaderEncoding (0.00s)
=== RUN   TestEmailFromReader
--- PASS: TestEmailFromReader (0.00s)
=== RUN   TestNonAsciiEmailFromReader
--- PASS: TestNonAsciiEmailFromReader (0.00s)
=== RUN   TestNonMultipartEmailFromReader
--- PASS: TestNonMultipartEmailFromReader (0.00s)
=== RUN   TestBase64EmailFromReader
--- PASS: TestBase64EmailFromReader (0.00s)
=== RUN   TestAttachmentEmailFromReader
--- PASS: TestAttachmentEmailFromReader (0.00s)
=== RUN   Test_base64Wrap
--- PASS: Test_base64Wrap (0.00s)
=== RUN   Test_quotedPrintEncode
--- PASS: Test_quotedPrintEncode (0.00s)
=== RUN   TestMultipartNoContentType
--- PASS: TestMultipartNoContentType (0.00s)
=== RUN   TestNoMultipartHTMLContentTypeBase64Encoding
--- PASS: TestNoMultipartHTMLContentTypeBase64Encoding (0.00s)
=== RUN   Test_quotedPrintDecode
--- PASS: Test_quotedPrintDecode (0.00s)
=== RUN   TestParseSender
--- PASS: TestParseSender (0.00s)
PASS
ok  	github.com/goravel/framework/mail	0.024s
=== RUN   TestMailMakeCommand
--- PASS: TestMailMakeCommand (0.00s)
PASS
ok  	github.com/goravel/framework/mail/console	0.009s

Edit: I just compared my fork with this repo, and neither one actually sent out an email.

Signed-off-by: Adam Jimerson <vendion@gmail.com>
@hwbrzzl
Copy link
Contributor

hwbrzzl commented Mar 22, 2025

Hey @vendion There is an issue with the mail test cases, I fixed it in the master branch, you can rebase your branch. Sorry for this. And I tested the header feature locally, it can be run normally, we are good to go.

image

@vendion
Copy link
Contributor Author

vendion commented Mar 23, 2025

Okay, just updated my branch with your changes.

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, thanks! I'll add you to the contributor list, looking forward to your next PR. 👍

@hwbrzzl hwbrzzl merged commit 5bf6b95 into goravel:master Mar 24, 2025
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting custom headers when sending mail

2 participants