PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] What component to use to send mail with any kind of body?

 July 18, 2022     c#, document-body, email, sendmail     No comments   

Issue

I made a mail sender in C# but I'm having trouble with the body of the mail. It only sends the texts without pictures, links and other elements. Not to mention, I used RichTextBox for that purpose.

So now my question is: what component to use to send mail with pictures, links and else?

I also enabled IsBodyHtml to true.

What I want to do is to copy the pictures, links and texts (with different colors and size) from Microsoft Word and paste it to control, and when user gets mail he gets the exact same body and layout as I send them.


Solution

You'll need to send it as html. Save your word doc as html and use that. For the images in your document you can either point to them via their absolute urls (publicly available via the internet).

Or you could use the LinkedResource class.

With the LinkedResource class your images have to specify a cid in the source.

var inlineLogo = new LinkedResource("path/myfile.png");
                                inlineLogo.ContentId = Guid.NewGuid().ToString(); 

var imageHtmlFragment = string.Format("<img alt='My Logo'  src='cid:{0}' style='width: 250px;height: 60px;'/>",inlineLogo.ContentId);

var newMail = new MailMessage();

var view = AlternateView.CreateAlternateViewFromString(imageHtmlFragment, null, "text/html");
                        view.LinkedResources.Add(inlineLogo);
                        newMail.AlternateViews.Add(view);


Answered By - scartag
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing