 |
|
 |
There is a problem with Spam, if I attach an image, Outlook or before it (SpamAssasin for example) sign email as a spam
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
 |
Outlook has never mark anything I send with this as spam. It depends on the content you add, not the images itself.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi,
Thanks for that. I actually learned a few things in there that I can make use of in other projects. If I have time someday I might update this project to not use the 3rd party dotnetmail, but for now it does the job so I'll just KISS (Keep It Simple Stupid)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
An easy way to embed images into HTML:
byte[] imgBuffer = File.ReadAllBytes(ImageFilePath); string imageHTML = string.Format("<img src=\"data:image/jpg;base64, {0}\" alt=\"Some image alt\"", Convert.ToBase64String(imgBuffer));
This works for HTML email, also. This converts an image (saved in a byte array) to a Base64 string. More information is at: http://en.wikipedia.org/wiki/Data:_URI_scheme
Note: some email clients treat emails with embeded images as though they are spam.
|
| Sign In·View Thread·PermaLink | 4.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Hi,
I am creating NewsLetter Templete(just like in outlook), using C#.NET, I am using that same templete to send email from web application.
currently i am giving the path of image as they are stored in web server, so how can i embed images for this problem....
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
Can i send embed images from local machine . i don't want to use SmtpServer. how can i do this
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
What do you mean you do not want to use SmtpServer? How else do you plan on sending the email? How do you normally send emails?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello.
I am what everyone calles a newbie to asp.net developement.
I am trying to build a newsletter sending application. My idea was to create a HTML page and simply add it to the e-mail body. Simple idea to start with but has turned out to be one heck of a brain wrecker.
I came across this site which seems to have what I need to pull this off. For the moment I have got to a point where, when I build my site I have just one error to take care of.
The error says that "The name imageNodes doesn't exist in the current context" I have VS-2005 installed in french so the error message is a literal translation.
The code that generates the error is at the bottom of this post.
Thanks in advance for any help.
I have also added the using statements that I am using in my c# code behind file, thinking that the problem might come from here:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Net; //using System.Net.Mail; //using System.Web.Mail; using System.IO; using System.Text; using DotNetOpenMail; using MIL.Html; using DotNetOpenMail.SmtpAuth;
//private HtmlNodeCollection imageNodes = new HtmlNodeCollection();
private void GetImageNodes(HtmlNodeCollection nodes) { foreach (HtmlNode node in nodes) { HtmlElement element = node as HtmlElement; if (element != null) { if (element.Name.ToLower() == "img") { imageNodes.Add(element); } if (element.Nodes.Count > 0) { GetImageNodes(element.Nodes); } } } }
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
hi. nice little app. anyway you can change the code so it takes flash??
Thanks A Bunch Saar Dagan Wanna Be Programmer
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Hi, I had problems with dotnetopenmail - could not connect to any SMTP servers but was able to use cdo directly with help from another posting.
Uses MILHTMLParser.dll to parse the HTML downloaded from -http://www.codeproject.com/dotnet/apmilhtml.asp
Uses cdosys.dll in system32 for email functionality. Great help from posting at - http://support.jodohost.com/showthread.php?t=7692
public void ConvertImagesToEmbeddedMailImages(string html, ref CDO.Message emailMessage) { HtmlDocument document = HtmlDocument.Create(html, false); HtmlNodeCollection imageNodes = new HtmlNodeCollection(); // Get All the img nodes GetImageNodes(document.Nodes, ref imageNodes); foreach (HtmlElement element in imageNodes) { string path = HttpContext.Current.Server.MapPath(element.Attributes["src"].Value); FileInfo imageFileInfo = new FileInfo(HttpContext.Current.Server.MapPath(element.Attributes["src"].Value)); string contentId = imageFileInfo.Name.Replace(imageFileInfo.Extension, string.Empty); CDO.IBodyPart bodyPart = emailMessage.AddRelatedBodyPart(path, contentId, CDO.CdoReferenceType.cdoRefTypeLocation, string.Empty, string.Empty); bodyPart.Fields.Append("urn:schemas:mailheader:Content-ID", DataTypeEnum.adVariant, 255, FieldAttributeEnum.adFldMayBeNull, string.Format("<{0}>", contentId)); bodyPart.Fields.Update(); //Change the src to "cid:" element.Attributes["src"].Value = string.Format("cid:{0}", contentId); } // set the email text to the modified html emailMessage.HTMLBody = document.HTML; }
private void GetImageNodes(HtmlNodeCollection nodes, ref HtmlNodeCollection imageNodes) { foreach (HtmlNode node in nodes) { HtmlElement element = node as HtmlElement; if (element != null) { if (element.Name.ToLower() == "img") { imageNodes.Add(element); } if (element.Nodes.Count > 0) { GetImageNodes(element.Nodes, ref imageNodes); } } } }
|
| Sign In·View Thread·PermaLink | 4.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
im having problems, or just confused w/ the code... i have my image, can you show me and example of the code that you would put in the email? w/ the image src or whatever.
thanks
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
I'm not sure what your problem is. The process is very simple, create your html file.
<html> <head> <title>The Code Project</title> </head> <body bgcolor="#FFFFFF" color=#000000> <p><img border="0" src="PSH_Ne2.jpg" width="400" height="300"></p> </body> </html>
Save it and then select it from the form as the "Original News Letter File". Add your Subject, Email From, Email To and Smtp Server and click send.
As simple as that. 
HTH
Let me know how it went.
Just another rocket scientist, NOT!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi,
Have no idea what you mean by analyze background images. If you mean how to get background images to work as well then all you need to do is change the code to look at the tags fro background images. I didn't need that functionality so I didn't add it.
HTH
Pieter
Just another rocket scientist, NOT!
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
Thanks for the tip! It might be beneficial (in your next version) to have an option to have the images sit on a web server and link to them from the email - that way users on slow connections don't have to wait for the images to download until they view the email.
Dirk Watkins
|
| Sign In·View Thread·PermaLink | 1.20/5 (2 votes) |
|
|
|
 |
|
 |
 That is not the point, you can do that with any html enabled email application like outlook. With this you do not get the anoying image placeholders when you open the email in outlook (which is a security feature) the images show immediately. And if you optimize your images the email should not be more than a couple of 100KB in the one I did for my sister the email was only 253KB big (and she used very high res pictures to start with) and with 56Kbs being the entry level modems these days that is not very big.
In anycase this is a choice you make when sending out your newsletter or email, if your audience has slow connections in general then don't use this method otherwise if they have fast connections then this is an option, but then again you need to look at the size of your images and the size of the email as well and make your dicision.
So thanks for the feedback and keep it coming.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I would recommend adding something like
else if (imageFileInfo.Extension == ".png") { relatedFileAttachment.ContentType = "image/png"; }
Since PNGs are becoming more popular. Or even just skip a step:
if (imageFileInfo.Extension == ".jpg") { relatedFileAttachment.ContentType = "image/jpeg"; } else { relatedFileAttachment.ContentType = String.Concat("image/", imageFileInfo.Extension.SubString(1)); }
So you can support most image types at once.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
yea cool I agree, but it was a quick and dirty to get something to work and I posted it just in case somebody else wants to or has been wondering how to do this. Like I said, this article is not about best practices I had to fit it in with a lot of other work so the priority wasn't a sparkling well written app, it needed to work and it needed to work in an hour.
I have had a request to expand it so that you can import an email list and email it off from the form. When I do that I will clean the code and repost it.
Thanks for your comments though, I will incorporate it.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |