Click here to Skip to main content
15,917,709 members
Home / Discussions / C#
   

C#

 
GeneralRe: Good vs Bad Pin
Eddy Vluggen12-Mar-15 1:25
professionalEddy Vluggen12-Mar-15 1:25 
AnswerRe: Good vs Bad Pin
Subramanyam Shankar17-Mar-15 1:47
professionalSubramanyam Shankar17-Mar-15 1:47 
QuestionPublic Key Data Encryption Pin
benchambers23310-Mar-15 23:11
benchambers23310-Mar-15 23:11 
AnswerRe: Public Key Data Encryption Pin
OriginalGriff10-Mar-15 23:50
mveOriginalGriff10-Mar-15 23:50 
QuestionHow to Crop Pdf page and save as image in c# winforms ? Pin
User 952119410-Mar-15 22:05
User 952119410-Mar-15 22:05 
AnswerRe: How to Crop Pdf page and save as image in c# winforms ? Pin
Pete O'Hanlon10-Mar-15 22:08
mvePete O'Hanlon10-Mar-15 22:08 
Questionhow to new vertical form Pin
fsdsc210-Mar-15 14:54
fsdsc210-Mar-15 14:54 
AnswerRe: how to new vertical form Pin
BillWoodruff10-Mar-15 19:19
professionalBillWoodruff10-Mar-15 19:19 
GeneralRe: how to new vertical form Pin
fsdsc212-Mar-15 5:37
fsdsc212-Mar-15 5:37 
GeneralRe: how to new vertical form Pin
BillWoodruff12-Mar-15 18:32
professionalBillWoodruff12-Mar-15 18:32 
GeneralRe: how to new vertical form Pin
fsdsc213-Mar-15 4:56
fsdsc213-Mar-15 4:56 
Questiona problem Pin
Akbar Fardi10-Mar-15 11:29
Akbar Fardi10-Mar-15 11:29 
AnswerRe: a problem Pin
Garth J Lancaster10-Mar-15 12:23
professionalGarth J Lancaster10-Mar-15 12:23 
AnswerRe: a problem Pin
manchanx10-Mar-15 13:25
professionalmanchanx10-Mar-15 13:25 
QuestionEmbed Image n Email Pin
Jassim Rahma10-Mar-15 10:37
Jassim Rahma10-Mar-15 10:37 
AnswerRe: Embed Image n Email Pin
Eddy Vluggen10-Mar-15 10:53
professionalEddy Vluggen10-Mar-15 10:53 
AnswerRe: Embed Image n Email Pin
Richard Deeming11-Mar-15 2:56
mveRichard Deeming11-Mar-15 2:56 
There's an example here[^].

There's also an example of creating attachments from a stream[^]. (The LinkedResource class works in a similar way.)

Combining the two would give you something like this:
C#
using (MailMessage mail = new MailMessage())
{
    mail.From = new MailAddress("me@mycompany.com");
    mail.To.Add("you@yourcompany.com");
    mail.Subject = "This is an email";
    
    AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain");
    AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<p>Here is an embedded image: <img src=\"cid:myimage\"></p>", null, "text/html");
    
    MemoryStream stream = new MemoryStream();
    theImage.Save(stream, ImageFormat.Jpeg);
    stream.Seek(0L, SeekOrigin.Begin);
    
    LinkedResource imageResource = new LinkedResource(stream, MediaTypeNames.Image.Jpeg);
    imageResource.ContentId = "myimage";
    htmlView.LinkedResources.Add(imageResource);
    
    mail.AlternateViews.Add(plainView);
    mail.AlternateViews.Add(htmlView);
    
    SmtpClient smtp = new SmtpClient("127.0.0.1");
    smtp.Send(mail);
}

You just need to make sure that each embedded resource has a ContentId which is unique within the message, and refer to the resource within the view as cid:ContentId.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


QuestionHow to cancel the change in a TextBox after I click on the Cancel button on a form, which was hidden form? Pin
pvpeng10-Mar-15 5:25
pvpeng10-Mar-15 5:25 
AnswerRe: How to cancel the change in a TextBox after I click on the Cancel button on a form, which was hidden form? Pin
Richard MacCutchan10-Mar-15 5:57
mveRichard MacCutchan10-Mar-15 5:57 
AnswerRe: How to cancel the change in a TextBox after I click on the Cancel button on a form, which was hidden form? Pin
Eddy Vluggen10-Mar-15 8:35
professionalEddy Vluggen10-Mar-15 8:35 
AnswerRe: How to cancel the change in a TextBox after I click on the Cancel button on a form, which was hidden form? Pin
BillWoodruff10-Mar-15 19:46
professionalBillWoodruff10-Mar-15 19:46 
QuestionHow to display just a part of a JPEG image Pin
Member 113687599-Mar-15 23:11
Member 113687599-Mar-15 23:11 
AnswerRe: How to display just a part of a JPEG image Pin
Gerry Schmitz10-Mar-15 1:27
mveGerry Schmitz10-Mar-15 1:27 
QuestionDisplay just a part of an image Pin
Member 113687599-Mar-15 23:10
Member 113687599-Mar-15 23:10 
QuestionWhat is the best practice for push database change notification Pin
Tridip Bhattacharjee9-Mar-15 3:41
professionalTridip Bhattacharjee9-Mar-15 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.