[#15] MailWindow: Add email sending feature

This commit is contained in:
2024-03-05 16:32:21 +01:00
parent 0812c6a8f9
commit 74da1ba46f
8 changed files with 137 additions and 37 deletions

View File

@ -5,6 +5,7 @@ using Elwig.Helpers;
using System.Collections.Generic;
using System.Linq;
using Elwig.Helpers.Printing;
using MimeKit;
namespace Elwig.Documents {
public abstract partial class Document : IDisposable {
@ -150,6 +151,16 @@ namespace Elwig.Documents {
Pdf.Show(_pdfFile.NewReference(), Title + (this is BusinessDocument b ? $" - {b.Member.Name}" : ""));
}
public MimePart AsEmailAttachment(string filename) {
if (PdfPath == null) throw new InvalidOperationException("Pdf file has not been generated yet");
return new("application", "pdf") {
Content = new MimeContent(File.OpenRead(PdfPath)),
ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
ContentTransferEncoding = ContentEncoding.Base64,
FileName = filename
};
}
private class MergedDocument(IEnumerable<Document> docs) : Document("Mehrere Dokumente") {
public IEnumerable<Document> Documents = docs;
}