Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

mailkit send attachment

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 ();

// Set the plain-text version of the message text
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
";

// We may also want to attach a calendar event for Monica's party...
builder.Attachments.Add (@"C:UsersJoeyDocumentsparty.ics");

// Now we just need to set the message body and we're done
message.Body = builder.ToMessageBody ();
Comment

mailkit send attachment


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?";

// create our message text, just like before (except don't set it as the message.Body)
var body = new TextPart ("plain") {
    Text = @"Hey Alice,

What are you up to this weekend? Monica is throwing one of her parties on
Saturday. I was hoping you could make it.

Will you be my +1?

-- Joey
"
};

// create an image attachment for the file located at path
var attachment = new MimePart ("image", "gif") {
    Content = new MimeContent (File.OpenRead (path)),
    ContentDisposition = new ContentDisposition (ContentDisposition.Attachment),
    ContentTransferEncoding = ContentEncoding.Base64,
    FileName = Path.GetFileName (path)
};

// now create the multipart/mixed container to hold the message text and the
// image attachment
var multipart = new Multipart ("mixed");
multipart.Add (body);
multipart.Add (attachment);

// now set the multipart/mixed as the message body
message.Body = multipart;

Comment

PREVIOUS NEXT
Code Example
Csharp :: asp.net core 3.1: cast jObject to dictionary<string,string 
Csharp :: substring c# after character 
Csharp :: difference between namespace and assembly in c# 
Csharp :: get the path of executable c# 
Csharp :: OnCollision update unity 
Csharp :: set textbox colour to transparent c# 
Csharp :: subtract two times c# 
Csharp :: untiy delet ke 
Csharp :: c# exit application 
Csharp :: check if string is a guid c# 
Csharp :: website link in unity 
Csharp :: dynamics 365 update record c# 
Csharp :: string to uint c# 
Csharp :: how to get all panels in form in c# 
Csharp :: c# date to string yyyy-mm-dd 
Csharp :: unserialized field unity 
Csharp :: C# metodas duomenu paemimui veiksmams ir grazinimui 
Csharp :: unity how to remove a tag 
Csharp :: system.linq.iorderedenumerable`2[system.char,system.char] çözümü 
Csharp :: how to make a partical system to destroy itself after it finishing 
Csharp :: how to get desktop name in c# 
Csharp :: unity agent does not move 
Csharp :: use only one class from a namespace in c# 
Csharp :: unity get list of children 
Csharp :: move object to mouse unity 
Csharp :: best practice c# check if string is null or whitespace 
Csharp :: includes method C# 
Csharp :: rigidbody.addtorque 
Csharp :: get length of a string c# 
Csharp :: C# HttpClient POST request 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =