| AttachmentCollectionAdd(String, CancellationToken) Method |
Add an attachment.
Namespace: MimeKitAssembly: MimeKit (in MimeKit.dll) Version: 4.7.1
Syntax public MimeEntity Add(
string fileName,
CancellationToken cancellationToken = default
)
Parameters
- fileName String
- The name of the file.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
MimeEntityThe newly added attachment
MimeEntity.
Exceptions Remarks Adds the specified file as an attachment.
Example var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("Joey", "joey@friends.com"));
message.To.Add (new MailboxAddress ("Alice", "alice@wonderland.com"));
message.Subject = "How you doin?";
var builder = new BodyBuilder ();
builder.TextBody = @"Hey Alice,
What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.
Will you be my +1?
-- Joey
";
var image = builder.LinkedResources.Add (@"C:\Users\Joey\Documents\Selfies\selfie.jpg");
image.ContentId = MimeUtils.GenerateMessageId ();
builder.HtmlBody = string.Format (@"<p>Hey Alice,<br>
<p>What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.<br>
<p>Will you be my +1?<br>
<p>-- Joey<br>
<center><img src=""cid:{0}""></center>", image.ContentId);
builder.Attachments.Add (@"C:\Users\Joey\Documents\party.ics");
message.Body = builder.ToMessageBody ();
See Also