Commit graph

85 commits

Author SHA1 Message Date
263f6bb3de
Refactor SMTP client code for better readability
The variable names in the code related to the I/O of the SMTP client have been clarified for improved readability and comprehension. For example, unclear variable names like `d` and `w` have been replaced with more meaningful names like `depth` and `writer`. The same naming improvements have also been applied to function parameters. This update aims to enhance code maintenance and simplify future development processes.
2024-02-24 12:43:01 +01:00
a864be059c
Add "X-Auto-Response-Suppress" header and update SetBulk method
A new "X-Auto-Response-Suppress" header has been added. The SetBulk method has been updated to include this new header, as it is recommended for automated emails. This functionality is tested in the msg_test.go file.
2024-02-08 16:45:06 +01:00
ef86a1a1fb
Add Charset support for message parts
Charset support has been added in the 'Part' struct. A 'SetCharset' method and a 'WithPartCharset' option have been added to override the default Part charset. The 'writePart' function in msgWriter now accommodates the charset defined at the Part level, defaulting to the previous functionality if not set.
2024-01-31 16:28:41 +01:00
0b622368ba
#166: Add delivery status indication for messages
This update introduces a new property, `isDelivered`, in the message struct to track if a message has been successfully sent or not. Additionally, this also includes a new helper function `IsDelivered` to easily retrieve the status. This feature enhances the tracking capabilities of outgoing messages across different client files.
2024-01-23 11:01:08 +01:00
rami
bd6250a8c2 Added return error to fileFromReader 2023-12-24 17:04:55 +01:00
da21550dc9
Fix potential null pointer exceptions in msg.go
This commit adds conditions in msg.go file to check if the header 'HeaderDispositionNotificationTo' key exists in the map 'm.genHeader' before trying to associate it with a value. This prevents potential null pointer exceptions.
2023-11-29 17:26:58 +01:00
ca896bd641
Refactor error checking in msg.SendErrorIsTemp()
Added an additional condition in the SendErrorIsTemp function within msg.go to ensure that the error e is not nil before referencing it. This guards against potential runtime panics from dereferencing a nil pointer, enhancing robustness of error handling.
2023-11-29 16:45:25 +01:00
a50a3ceb18
Add validation for nil STDERR or STDIN pipe
Introduced a new condition that checks and returns an error if either STDERR or STDIN pipe is nil in the msg function of msg.go. This improves error handling by preventing potential panic due to referencing a nil pipe.
2023-11-29 16:43:50 +01:00
1a166770b7
Update range loop to improve msg function readability
Converted the range loop in the GetAddrHeaderString function in msg.go to use value semantics rather than index notation. This improves code clarity by not unnecessarily referring to m.addrHeader[h] in the loop and instead referencing the value directly (using variable mh), making it easier to understand and maintain.
2023-11-29 16:42:07 +01:00
468e1e2b2c
Protect against empty address list, refactor error handling
Added a condition to prevent assignment of an empty address list to the 'HeaderFrom' scenario. This eliminates potential runtime errors when trying to access an nonexistent element of a slice.
Adjusted error handling in the sendmail execution part by reusing the 'err' variable, promoting cleaner, more readable code.
2023-11-20 18:36:19 +01:00
cc14864129
#152: Add new methods and tests for handling email addresses
Added new methods `ToFromString()`, `CcFromString()` and `BccFromString()` in msg.go file to handle strings of comma-separated email addresses.
2023-11-10 18:07:56 +01:00
leahoop
3c2c106cb4 #147 add remove attachments and embeds methods 2023-10-20 10:21:03 +08:00
438cfd60eb
Preparation for the v0.4.0 release:
- Bump version in doc.go
- Add sonarlint to .gitignore
- Update README to reflect the changes and contributors
- Fixed typos in auth_cram_md5_118.go, msg.go, msg_test.go, reader.go and smtp_ehlo_117.go
2023-05-31 09:34:45 +02:00
Christian Vette
20fe4cd751
fix: parsing of ReplyTo with special characters 2023-03-07 10:51:15 +01:00
fa0b9709f6
Correct method names in caveat comment 2023-01-31 21:57:10 +01:00
d33f0e8004
Merge branch 'main' into feature/107_provide-more-ways-for-middleware-to-interact-with-mail-parts 2023-01-31 20:47:36 +01:00
dab860834a
Adding PGPType to Msg as preparation to support PGP/MIME in go-mail-middleware 2023-01-31 18:35:48 +01:00
c9794069cd
Add Caveat note about the io.Reader methods being memory inefficient 2023-01-31 17:48:19 +01:00
e66ad2be1a
Fix Attach/EmbedReader and implement Attach/EmbedReadSeeker
This PR addresses #110.
`Msg.AttachReader()` would not output the attached file after consecutive writes (e.g. a write to a file and then send via Client).

This PR fixes this behaviour by first reading the io.Reader into memory and then creating a new `bytes.Reader`, which does support seeking. In the writeFunc we then seek to position 0 after a successful `io.Copy`. This is probably not the most memory efficient way of handling this, but otherwise we'll have to break the `io.Reader` interface.

Additionally, a new way of attaching/embedding files has been added: `Msg.AttachReadSeeker()` and `Msg.EmbedReadSeeker()` which take a ´io.ReadSeeker` as argument instead. These two methods will skip the reading into memory and make use of the `Seek` method of the corresponding interface instead.
2023-01-31 17:38:31 +01:00
25e00c64e2
Introduce GetEmbeds() and SetEmbeds()
These two methods work analogous to the `*Attachments()` methods and provide the user with access to the embedded files.
2023-01-29 13:48:51 +01:00
9724a2b523
Introducing Msg part deletion
This PR introduces a new struct field for the message parts: `del`

If the del flag is set to `true`, the msgWriter will ignore this part during the writing process.

Additionally, the `part` has now a `Delete` method that lets the user mark the part as deleted

This allows middleware to take further control of the Msg and is part of #107
2023-01-28 14:39:14 +01:00
3922d3f195
Switched copyright header from me to "The go-mail Authors" 2023-01-15 16:14:19 +01:00
5897bddd11
Update msg.go
Co-authored-by: iwittkau <iwittkau@users.noreply.github.com>
2023-01-02 22:29:10 +01:00
dbb596893d
Update msg.go
Co-authored-by: iwittkau <iwittkau@users.noreply.github.com>
2023-01-02 22:28:39 +01:00
f6709e90cd
Make golangci-lint happy by using errors.As instead of using type assertion on error (which can fail on wrapped errors) 2023-01-01 14:25:00 +01:00
78df991399
Proposal change for #90
Did a complete overhaul of the senderror.go.

- the list of `errors.New()` has been replaced with constant itoa error reasons as `SendErrReason`. Instead, the `Error()` method now reports the corresponding error message based on the reason.
- The `SendError` received a `Is()` method so that we can use `errors.Is()` for very specific error checking. I.e. we can check for `&SendErrors{Reason: ErrSMTPMailFrom, isTemp: true}`. This provides much more flexibility in the error checking capabilities
- A `isTemp` field has been added to the `SendError` type, indicating whether the received error is temporary and can be retried or not. Accordingly, the `*Msg` now has a `SendErrorIsTemp()` method indicating the same. The decision is based on the first 3 characters returned from the SMTP server. If the error code is within the 4xx range, the error is seen as temporary
- A test for the SendError type has been added
2023-01-01 14:20:13 +01:00
47bff15de9
Introduction of a Msg error type as proposal for #90
This PR introduces the `SendError` type which implements the error interface.

A new `senderror` field has been added to the `Msg` as well, so introduce this type to it.

I've also added different error variables that indicate the different things that can go wrong during mail delivery. These variables can be checked for, for each `Msg` using the `errors.As` method

The `Error()` method of `SendError` will return a detailed error string on why the `Msg` could not be delivered.

Additionally, `HasSendError()` and `SendError()` methods have been added to `Msg`. While `HasSendError()` simply returns a bool in case a `Msg` failed during delivery, the `SendError()` will return the full `SendError` error interface.
2022-12-31 12:40:42 +01:00
17b9d2ccf6
#80: GetAddrHeader and SetGenHeader
This PR introduces two major changes:

* SetHeader and SetHeaderPreformatted have been deprecated in favour of SetGenHeader and SetGenHeaderPreformatted
  As pointed out in #80 the naming was pretty confusing, given that we already have SetAddrHeader. With the new naming convention it should be more clear. For compatibility reasons the old methods have been kept for now but in reality they are just aliases to the new methods
* GetAddrHeader and GetAddrHeaderString have been introduced
  As requested in #80 analogous to GetGenHeader we also need a similar method for the address headers. Since address headers are *mail.Address pointer, we've also added a *String method that will extract the address string and return a string slice instead
  Additionally we're introducing methods for the actual address headers: GetTo, GetFrom, GetCc and GetBcc (with a *String counterpart as well). This way the user has full flexibility. Either they use the more "low-level" GetAddrHeader method or the higher level methods for the corresponding address type
2022-11-19 11:22:20 +01:00
d327ca73e4
The new messageID generated with #76 is a bit too long by default. This patch reduces the length 2022-10-26 15:48:48 +02:00
2e60d070a6
Add SetHeaderPreformatted() method
With the SetHeaderPreformatted() method we have the ability to set headers that are already preformatted by the user and will not be altered in the mail message output
2022-10-26 15:33:03 +02:00
8484e557d0
Replace math/rand with crypto/rand
Since the Windows tests were still failing, we are replacing the random number generation with math/rand with random string generation via crypto/rand
2022-10-26 14:05:25 +02:00
5bf0c10525
Randomness apparently not good enough for windows. Tests were failing. This fix improves it 2022-10-26 13:43:51 +02:00
021e003e78
Closes #74
This fix makes sure that generated message IDs via SetMessageID() are truly random and unique
2022-10-26 11:59:03 +02:00
2bd6851c78
Fix in the storage of the original Middleware 2022-10-25 16:56:40 +02:00
6f93e5835e
Introducing MiddlewareType and WriteToSkipMiddleware
For middlewares to be able to access the fully written mail message, we need a way to execute WriteTo without the calling middleware to be handled, otherwise we end up in an infinite loop

Therefore, this PR introduces the MiddlewareType and the corresponding change of the Middleware interface. We now require to return the MiddlewareType when the Type() method on the interface is called

This way we can also introduce the WriteToSkipMiddleware method which takes a MiddlewareType as argument. This will allow us to use a WriteTo call with the initiating Middleware to be skipped
2022-10-25 16:42:18 +02:00
b6beeb5cae
Finalized the Reader type and removed the broken Read() method 2022-10-20 18:26:51 +02:00
183fb347d6
Fix create header maps in case SetHeader or SetAddrHeader is called on an empty Msg type 2022-10-20 18:06:26 +02:00
5faa6dfbd6
We now return a Reader instead of the io.Reader interface 2022-10-20 18:03:57 +02:00
966615584d
Implement a proper io.Reader interface since the current implementation is flawed 2022-10-20 15:52:53 +02:00
Dhia Gharsallaoui
b94a42ebe8
Expose Msg attachments fields 2022-10-12 13:36:52 +02:00
dbe58745be
#60 Working on Get/Set methods to access the Msg part slice
Still some tests needed
2022-10-11 17:05:44 +02:00
cd2ee86846
Added GetGenHeader to the Msg to grant read access to set generic headers (e g. to use in Middlewares) 2022-10-02 12:25:49 +02:00
dhia gharsallaoui
a4733f0618 Implement middleware concept and their test 2022-09-22 18:05:47 +02:00
c1d4dbedee
Remove not needed loop from RequestMDNAddTo 2022-09-09 11:39:08 +02:00
46001dc691
Added support for requesting MDNs as described in RFC 8098 2022-09-09 11:35:45 +02:00
192627f6a5
Closes #29: Allow attaching/embedding from embed.FS
- Added `EmbedFromEmbedFS()` to allow embedding from embed.FS
- Added `AttachFromEmbedFS()` to allow attaching from embed.FS
- Added `fileFromEmbedFS()` as internal method for both other m
  methods to attach/embed the embed.FS file
2022-07-07 10:46:57 +02:00
31001e87b2
#24: Add SPDX license IDs for REUSE compliance
# SUMMARY

* Bad licenses:
* Deprecated licenses:
* Licenses without file extension:
* Missing licenses:
* Unused licenses:
* Used licenses: CC0-1.0, MIT
* Read errors: 0
* Files with copyright information: 45 / 45
* Files with license information: 45 / 45

Congratulations! Your project is compliant with version 3.0 of the REUSE Specification :-)
2022-06-17 15:05:54 +02:00
a50910b943
#21: Add possbility to set dedicated envelope from address
- Added `EnvelopeFrom()` and `EnvelopeFromFormat()` methods analogous to the `From()` `FromFormat()` methods
- Changed MsgWriter logic for envelope from addresses
- Adjusted `Msg.GetSender()` to return the envelope from first and only mail body from if the envelope is not set
2022-06-13 10:18:35 +02:00
95100545d6
#18: Added Msg.WriteToFile which allows storing the Msg in a file 2022-06-06 16:43:04 +02:00
97e1386e36
Code smell fix for #13
SonarQube identified two code smells for duplicate string usage
2022-06-03 12:27:26 +02:00