Click here to Skip to main content
15,902,938 members
Home / Discussions / C#
   

C#

 
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 
AnswerRe: What is the best practice for push database change notification Pin
Eddy Vluggen9-Mar-15 4:15
professionalEddy Vluggen9-Mar-15 4:15 
GeneralRe: What is the best practice for push database change notification Pin
Tridip Bhattacharjee9-Mar-15 4:33
professionalTridip Bhattacharjee9-Mar-15 4:33 
GeneralRe: What is the best practice for push database change notification Pin
F-ES Sitecore9-Mar-15 5:29
professionalF-ES Sitecore9-Mar-15 5:29 
GeneralRe: What is the best practice for push database change notification Pin
Tridip Bhattacharjee9-Mar-15 21:25
professionalTridip Bhattacharjee9-Mar-15 21:25 
GeneralRe: What is the best practice for push database change notification Pin
Gerry Schmitz10-Mar-15 1:16
mveGerry Schmitz10-Mar-15 1:16 
GeneralRe: What is the best practice for push database change notification Pin
Tridip Bhattacharjee10-Mar-15 3:15
professionalTridip Bhattacharjee10-Mar-15 3:15 
GeneralRe: What is the best practice for push database change notification Pin
Gerry Schmitz10-Mar-15 11:35
mveGerry Schmitz10-Mar-15 11:35 
GeneralRe: What is the best practice for push database change notification Pin
Eddy Vluggen9-Mar-15 6:52
professionalEddy Vluggen9-Mar-15 6:52 
GeneralRe: What is the best practice for push database change notification Pin
Tridip Bhattacharjee9-Mar-15 21:18
professionalTridip Bhattacharjee9-Mar-15 21:18 

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.