File tree Expand file tree Collapse file tree
SquidStd.Mail.Abstractions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ dotnet add package SquidStd.Mail.Abstractions
2828| ` MailReceivedEvent ` | Published on the event bus per new message. |
2929| ` IMailReader ` | Fetches new messages from a mailbox. |
3030| ` MailOptions ` | Host/port/credentials, protocol, polling and fetch options. |
31+ | ` IMailSender ` | Sends outbound email. |
32+ | ` OutgoingMailMessage ` | An email to send (recipients, subject, bodies, attachments). |
33+ | ` SmtpOptions ` | SMTP host/port/SSL/credentials and a default sender. |
34+ | ` MailSentEvent ` / ` MailSendFailedEvent ` | Published on the event bus on send success/failure. |
3135
3236## License
3337
Original file line number Diff line number Diff line change @@ -44,6 +44,36 @@ container.AddMail(new MailOptions
4444Listen with an ` IAsyncEventListener<MailReceivedEvent> ` registered on the ` IEventBus ` . IMAP marks messages
4545` \Seen ` after fetch (configurable); POP3 dedups by UIDL and can delete after download.
4646
47+ ## Sending (SMTP)
48+
49+ ``` csharp
50+ using DryIoc ;
51+ using SquidStd .Mail .Abstractions .Data ;
52+ using SquidStd .Mail .Abstractions .Data .Config ;
53+ using SquidStd .Mail .Abstractions .Interfaces ;
54+ using SquidStd .Mail .MailKit .Extensions ;
55+
56+ container .AddMailSender (new SmtpOptions
57+ {
58+ Host = " smtp.example.com" ,
59+ Port = 587 ,
60+ UseSsl = false ,
61+ Username = " user@example.com" ,
62+ Password = " secret" ,
63+ DefaultFrom = new MailAddress (" App" , " app@example.com" )
64+ });
65+
66+ var sender = container .Resolve <IMailSender >();
67+ await sender .SendAsync (new OutgoingMailMessage
68+ {
69+ To = [new MailAddress (" Bob" , " bob@example.com" )],
70+ Subject = " Welcome" ,
71+ HtmlBody = " <p>Hello!</p>"
72+ });
73+ ```
74+
75+ ` MailSentEvent ` / ` MailSendFailedEvent ` are published on the ` IEventBus ` ; failures throw ` MailSendException ` .
76+
4777## License
4878
4979MIT — part of [ SquidStd] ( https://github.com/tgiachi/squid-std ) .
You can’t perform that action at this time.
0 commit comments