Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6132027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:03:01+00:00 2026-05-23T17:03:01+00:00

I wish to send an email, with a plain text and html version. The

  • 0

I wish to send an email, with a plain text and html version. The email needs an image to go with it (not one I can host somewhere else), it should be embedded if the client views it in html, and attached for the plain text view.

Is this possible to do that would work in all common clients?

The closest I have come is creating the image as an attachment (rather than a linked resource) then referencing it in the html with cid:filename.jpg. However this doesn’t work in gmail (it doesn’t display the image in the html).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:03:01+00:00Added an answer on May 23, 2026 at 5:03 pm

    This code snippet works in outlook 2010 and gmail. I test the plain text email by temporarily putting the plain text part last in the email, which makes gmail use that.

    It also demonstrates some other cool stuff such as email templates and tag substitution.

    
    public void SendEmailWithPicture(string email, byte[] image)
    {
        string filename = "AttachmentName.jpg";
    
        LinkedResource linkedResource = new LinkedResource(new MemoryStream(image), "image/jpg");
        linkedResource.ContentId = filename;
        linkedResource.ContentType.Name = filename;
    
        this.Send(
            EmailTemplates.sendpicture,
            this.Subjects.SendPicture,
            new List() { email },
            this.ReplyTo,
            tagValues: new Dictionary() { { "ImageAttachmentName", "cid:" + filename } },
            htmlLinkedResources: new List() { linkedResource }
            );
    }
    
    private void Send(EmailTemplates template, string subject, List to, string replyTo,
        Dictionary tagValues = null, List attachments = null, List htmlLinkedResources = null)
    {
        try
        {
            MailMessage mailMessage = new MailMessage();
    
            // Set up the email header.
            to.ForEach(t => mailMessage.To.Add(new MailAddress(t)));
            mailMessage.ReplyToList.Add(new MailAddress(replyTo));
            mailMessage.Subject = subject;
    
            string fullTemplatePath = Path.Combine(this.TemplatePath, EMAIL_TEMPLATE_PATH);
    
            // Load the email bodies
            var htmlBody = File.ReadAllText(Path.Combine(fullTemplatePath, Path.ChangeExtension(template.ToString(), "html")));
            var textBody = File.ReadAllText(Path.Combine(fullTemplatePath, Path.ChangeExtension(template.ToString(), "txt")));
    
            // Replace the tags in the emails
            if (tagValues != null)
            {
                foreach (var entry in tagValues)
                {
                    string tag = "{{" + entry.Key + "}}";
    
                    htmlBody = htmlBody.Replace(tag, entry.Value);
                    textBody = textBody.Replace(tag, entry.Value);
                }
            }
    
            // Create plain text alternative view
            string baseTxtTemplate = File.ReadAllText(Path.Combine(fullTemplatePath, TXT_BASE_TEMPLATE));
            textBody = baseTxtTemplate.Replace(TAG_CONTENT, textBody);
            AlternateView textView = AlternateView.CreateAlternateViewFromString(textBody, new System.Net.Mime.ContentType("text/plain"));
    
            // Create html alternative view
            string baseHtmlTemplate = File.ReadAllText(Path.Combine(fullTemplatePath, HTML_BASE_TEMPLATE));
            htmlBody = baseHtmlTemplate.Replace(TAG_CONTENT, htmlBody);
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, new System.Net.Mime.ContentType("text/html"));
            // Add any html linked resources
            if (htmlLinkedResources != null)
            {
                htmlLinkedResources.ForEach(lr => htmlView.LinkedResources.Add(lr));
                htmlLinkedResources.ForEach(lr => textView.LinkedResources.Add(lr));
            }
    
            // Add the two views (gmail will always display plain text version if its added last)
            mailMessage.AlternateViews.Add(textView);
            mailMessage.AlternateViews.Add(htmlView);
    
            // Add any attachments
            if (attachments != null)
            {
                attachments.ForEach(a => mailMessage.Attachments.Add(a));
            }
    
            // Send the email.
            SmtpClient smtp = new SmtpClient();
            smtp.Send(mailMessage);
        }
        catch (Exception ex)
        {
            throw new Exception(String.Format("Error sending email (to:{0}, replyto:{1})", String.Join(",", to), replyTo), ex);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to send an email from my localhost machine (using PHPs mail function)
I wish to send text between processes. I have found lots of examples of
I have created one windows service which send an email notifications to users (list
How can i send an email certain days from now in C# (Win Forms).
I wish to send mail to an administrator when the application crashes. So I
I wish to code a little service where I will be able to send
I wish I were a CSS smarty .... How can you place a div
I am desiring to send an email in R with an attachment using gmail.
I'm using PEAR's Mail package to send email from my script. I'm pretty sure
I am creating an iPhone app where the user can send their work in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.