Skip to content

Commit dfaf060

Browse files
Updates the documents.
1 parent 4ab9ff4 commit dfaf060

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Emailing/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ and one of its concrete implementations (for example
4444
- Central `IEmailManager` to create and send emails.
4545
- Pluggable `IEmailProvider` to send the final `EmailMessage` (transport-agnostic design).
4646
- Support of the *Importance* of the e-mails (**Low, Normal and High).
47+
- Support for sending emails with attachments.
4748

4849
## Basic concepts
4950

@@ -206,7 +207,22 @@ invitationEmail.Recipients.Add(
206207
});
207208
```
208209

209-
### 3. Send the email
210+
### 3. Add attachments (optional)
211+
212+
You can add attachments to the email by using the `Attachments` collection
213+
of the `EmailMessage` class:
214+
215+
```csharp
216+
using var fileContent = File.OpenRead("document.pdf");
217+
218+
invitationEmail.Attachments.Add(new EmailAttachment("MyFile.pdf", "MimeTypes.Pdf", fileContent));
219+
```
220+
221+
> **Note:** The `IEmailManager.SendAsync()` method will read the content of the attachment stream
222+
> but will not dispose of it. Make sure to manage the `Stream` lifetime appropriately
223+
> by calling the `Dispose()` method on the `Stream` instance after the email has been sent.
224+
225+
### 4. Send the email
210226

211227
Once the email and its recipients are configured, you ask the `IEmailManager` to send it:
212228

@@ -224,6 +240,8 @@ Under the hood:
224240
- The configured sender (`EmailingOptions.SenderEmailAddress`).
225241
- The recipient address and display name.
226242
- The generated subject and HTML content.
243+
- The importance.
244+
- The associated attachments.
227245
4. It calls `IEmailProvider.SendAsync(...)` to actually send the message.
228246

229247
The provider implementation is responsible for the technical details (SMTP, Azure Communication Service, etc.).

0 commit comments

Comments
 (0)