Background:
I am sending HTML emails from Oracle using XSLT.
XML is transformed using XSL and sent to stored procedure from .NET 4. The XSL processor is System.Xml.Xsl.XslCompiledTransform.
My custom Oracle Stored Procedure SEND_MAIL_HTML calls UTL_SMTP
Outlook receives e-mail and the picture is Red X. <-- problem
Using View Source, copy all the content into a file and save.
Double-click on the file and the picture shows up fine.
The img tag in my HTML has a src="data:image/jpeg;base64, LotsOfAlphanumerics" element.
Please ask me how to clarify the problem and I will.
I tried hard to make the cid method work, per the URL's below, but I ended up spending too much time on it.
In the end, I ended up posting the image to a public URL.
See also:
http://www.oracle-base.com/articles/misc/html-with-embedded-images-from-plsql.php
embedding image in html email
Send a base64 image in HTML email
Related
First of all, I want to start what I want and whats my issue, and to clarify that I'm using dbmail (SQLServer) for the sending process, and the main issue is that I donĀ“t get it to work with Gmail.
I need to send mails with integrated images (embedded or attached is the only possibility), but I can't seem to be able to achieve this without linking the images into a dedicated image hosting server.
I've tried embedding with base64 but images sometimes get a length of 6000 characters, and when the stored procedure that I've created gets executed the mail arrives empty and when I check the table sysmail_faileditems they body column appears with an empty value so I guess that the mail gets truncated because of the length of the base64 image.
And when I send the email with the image attached and reference it in src field it never loads where it's supposed to, it just shows as an attachment. This is maybe because of the security policies of Gmail, but in Outlook for desktop works just fine with this setup.
Thanks in advance.
Edit #1: In response to #AlwaysLearning, I will proced to show how I implemented the mentioned methods.
1 Attachment method:
SQL Code:
#file_attachments = 'C:\images\image.jpg'
HTML Code:
<img src="image.jpg" />
2 Base64 method:
SQL Code:
--in this method, I store the image in a base64 as a varchar(MAX)
--in a table and replace it in the stored procedure in execution time.
Set #emailbody = Replace(#emailbody,'^^IMAGE^^' ,#imagebase64)
HTML Code:
<img alt="image" width=200 height=86 src="^^IMAGE^^"/>
The real issue is that both these methods actually work with some email clients, but not with gmail, so obviously I'm missing some specifics or it's impossible to do it this way.
Please bear with me; there's a long story coming up. It's about programatically creating HTML e-mails from Delphi-7, sending them to Outlook, and not showing the pictures in it, so if you don't know anything about that, don't bother reading it all.
I have an application that sends variable-text E-mails, from a Delphi-7 program, to Outlook. I'm using a TMailInfo item, use a template HTML file for layout, replace placeholders with data from the program (%NAME% becomes "Johnson" etc), create a new Outlook message and populate HTMLbody with my result. All of this works fine.
Recently my client sent me a new sample message, asking me if I could change this E-mail to the new layout as he sent me. So I saved the E-mail as html (from Outlook, generating a huge HTML file full of code that is hardly understandable for a non-HTML guru like me)), replaced the static data with my placeholders, and saved it as the new template.
This worked fine except for one thing - the new layout included some local pictures (not available from a public web resource). When original sample mail from outlook, two things were created - a htm file with the html code, named "Subject" AND a folder called "Subject_files", containing the picture files plus a filelist.xml and an mso file.
The generated HTML refers to the pictures as src="subject_files/image001.jpg"> etc.
When I send the HTML to Outlook, it obviously has no idea where the images are - but how do I tell him?
What I tried:
copying the "subject_files" folder to "My Documents"
hardcoding the links to the pictures in several formats (i.e.
src="C:/test/subject_files/image001.jpg",
src="C://test/subject_files/image001.jpg",
src="C:\test\subject_files\image001.jpg",
and the like
but both don't work... so my question is really, how do I tell Outlook where to look for image files when programatically creating an HTML message?
Thanks in advance!
Once you the email, the recipient does not have access to your computer, So the images won't show in the email. to send images in an email you can:
Use aboslute links
<img src="http://www.example.com/images/header.jpg">
Use embedded images
Convert your images to BASE64, you can find many web sites online to that like
https://www.base64-image.de/ then
<img src="data:image/jpg;base64,/*base64-generated-string*/" />
As mentioned by Remy, the images can be added as regular attachments. You will then need to set the PR_ATTACH_CONTENT_ID property (DASL name http://schemas.microsoft.com/mapi/proptag/0x3712001F) using Attachment.PropertyAccessor.SetProperty. The HTML body must use the matching value for the cid attribute - <img src="cid:xyz">, where "xyz" is the value of the PR_ATTACH_CONTENT_ID property.
I just want to automate a web application, where that application parses the HTML page and pulls all the HTML Tags inner text based on some condition like if we have a tag called Span Example has given whose class="spanclass_1"
This is span tag...
which has particular class id. so that app parses and pulls that span into it.
And here the main pain area is, I should not use the developer code to automate that same parsing the HTML.
I want to automate that parsing done correctly, simply by using the parsed data which is shown in UI.
Any help, would be great.
Appreciating your time reading this.
(Note span tag is not shown)
Thanks buddies.
not enough details.
is this html page just a file in local filesystem on it is internet webpage?
do u have access to pages? can u modify it ? if answer yes, that just add javascript to page which will extract data and post to server.
if answer not, than it depends on language u use to programm.
Find good framework to parse html. load page parse it and extract data. Several situation can be there.
Worse scenario - page generated on client side using js.
Best scenario - page is in xhtml mode( u are lucky. any xml parser will help to build dom and extract data)
So so - page is simple html format (try several html parser to find most suitable for u)
So let's say that there is a HTML (or XHTML) code and
<img alt="...." src=".......aspx" />:
So, aspx generates image file, and there will be some image shown.
Now I want to send the generated image file to E-mail or using HTML form code, and I want my html code to do this automatically.
So, in the html code, after img code, I'd like to add codes that send the generated image automatically.
(I want a single code with img code and E-mail or HTML form code.)
What should I do?
To be honest, based on your question, it's not entirely clear what you're trying to accomplish. But, from what I gather, you could try several different approaches:
Check out this StackOverflow post: Sending an email with an image embedded in the body from C#
You can use the code from this source as a starting point: http://www.codedigest.com/Articles/ASPNET/95_Sending_Email_using_C__and_ASPNet_20.aspx (see "Sending Email with Embedded Image in the Message Body" section)
What you need to do is move the image generation logic to some library or the App_Code folder, and then call that logic twice: once from the .aspx handler that sends it for the tag, and once for the code that you also need to write that will send it in the email. Once you have the byte[] array with the image, follow lkaradashkov's link to send it in the email:
Sending an email with an image embedded in the body from C#
I am using JavaMail to send an e-mail. My goal is to send the contents of an xml file formatted by an xsl file as the message of the e-mail. Is this possible?
I know that the following code can be used to send a string containing html.
message.set.Content(htmlString, "text/html");
Am I correct in my assumption that the formatting information to create a html message in an e-mail must be embedded in the html and that there is no way to connect to a css?
If this is so, then the same must apply to xml and xsl.
If there is a way to join an existing xml file and an existing xsl file in the body of a JavaMail e-mail, I would be very grateful to anyone who can give me the code that makes this possible.
If it is impossible, I will be happy to be informed of this and pointed in the right direction. I suspect that I will need to parse the xml file and convert it to a string containing html formatting.
Thank you.
It's true that most email clients will not process CSS. Here's a chart.
As a result, it's commonplace to apply formatting by transforming the CSS-formatted HTML to an inline-style that most email clients can handle. Sometimes this is done by preprocessing the document with XSLT.
If you want to take this route, I suggest you look at the Saxon XSLT processor to preprocess your XML document.
Another option to handle this problem would be something like Emogrifier, Premailer, or even this SO Question. Which processes a CSS and HTML into one inline-styled email-safe document.