Author |
|
wenditaranto Newbie
Joined: 08 January 2015
Online Status: Offline Posts: 6
|
Posted: 08 January 2015 at 9:45am | IP Logged
|
|
|
Hello all,
I am having trouble with ImportRelatedFiles and hoping I could get some direction here.
I have a .eml file (below, oValue.ToString()) that contains the following html:
[CODE}<img alt=3D"" src=3D"/Temp/Uploads/screenshot.PNG" />[/CODE}
My code is below, using URI. The path is correct and I can use it to reference the image in a browser.
[CODE}
Dim oMessage As New MailBee.Mime.MailMessage
oMessage.BodyHtmlText = oValue.ToString()
oMessage.Builder.RelatedFilesFolder = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)
bResult = oMessage.ImportRelatedFiles(ImportRelatedFilesOptions.ImportFromUris)
bResult = oMessage.SaveMessage(sPath & "/msg.eml")
Dim sHTML As String = System.IO.File.ReadAllText(sPath & "/msg.eml")
[/CODE}
I've also tried disk path. The path is correct and I can use it to reference the image in explorer.
[CODE}
Dim oMessage As New MailBee.Mime.MailMessage
oMessage.BodyHtmlText = oValue.ToString()
oMessage.Builder.RelatedFilesFolder = System.Web.HttpContext.Current.Server.MapPath("..")
bResult = oMessage.ImportRelatedFiles(ImportRelatedFilesOptions.ImportFromUris)
bResult = oMessage.SaveMessage(sPath & "/msg.eml")
Dim sHTML As String = System.IO.File.ReadAllText(sPath & "/msg.eml")
[/CODE}
In either case, after this code runs, sHTML equals:
[CODE}<img alt=3D"" src=3D"/Temp/Uploads/screenshot.PNG" />[/CODE}
What am i missing here? I want this image references to be encoded inline.....
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 08 January 2015 at 10:09am | IP Logged
|
|
|
First, please make sure you're using the latest version of MailBee.NET. In NuGet console, run
Install-Package MailBee.NET
Also I wouldn't recommend semi-absolute paths. The path should either be "Temp/Uploads/screenshot.PNG" (relative path) or "http://www.host.com/Temp/Uploads/screenshot.PNG" (absolute path).
"/Temp/Uploads/screenshot.PNG" is a kind of path which is hard to resolve when the context is not a web page in the browser. The browser, when opened at www.host.com page knows that "/" is the root of the web site. But when you're using MailBee, MailBee doesn't know that because it is not being run under the context of the browser.
Regards,
Alex
|
Back to Top |
|
|
wenditaranto Newbie
Joined: 08 January 2015
Online Status: Offline Posts: 6
|
Posted: 08 January 2015 at 1:36pm | IP Logged
|
|
|
hi there, thank you for your reply.
I ran the nuget package update. I don't have much control over the path written to html because this is being done by a 3rd party rich text editor. however, i decided to intercept the value before maillbee.net gets it and remove the leading forward slash. same result. no errors, but no embedded image either.
Code:
Dim sHTML As String = oValue.ToString
sHTML = sHTML.Replace("src=""/Temp/Uploads/", "src=""Temp/Uploads/")
Dim oMessage As New MailBee.Mime.MailMessage
oMessage.BodyHtmlText = sHTML
oMessage.Builder.RelatedFilesFolder = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) & "/" 'tried with and w/o ending "/"
bResult = oMessage.ImportRelatedFiles(ImportRelatedFilesOptions.ImportFromUris)
bResult = oMessage.SaveMessage(sPath & "/msg.eml")
sHTML = System.IO.File.ReadAllText(sPath & "/msg.eml")
|
|
|
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 08 January 2015 at 2:18pm | IP Logged
|
|
|
Try to debug it with all things hardcoded. I.e. prepare a very simple HTML text
Code:
MailMessage msg = new MailMessage();
msg.Builder.RelatedFilesFolder = @"D:\";
msg.BodyHtmlText = "<html><body><img src=\"Temp/pic.png\"></body></html>";
msg.ImportRelatedFiles(ImportRelatedFilesOptions.ImportFromUris);
msg.SaveMessage(@"D:\Temp\msg.eml");
|
|
|
and put pic.png into D:\Temp
This code works for me. From this point, you can go next step and hardcode more complex values to find out the moment when it stops working. For instance, your RelatedFilesFolder + path_from_img_src does not designate a valid full path (but there can be dozens of other reasons, that's why step by step approaching to your initial code is required).
Currently, your code does not have hardcoded input values so it cannot be debugged.
Regards,
Alex
|
Back to Top |
|
|
wenditaranto Newbie
Joined: 08 January 2015
Online Status: Offline Posts: 6
|
Posted: 09 January 2015 at 6:59am | IP Logged
|
|
|
Hi Alex,
Thank you for the direction. I did find out the culprit.
What I didn't mention previously (I did not realize it was important) is that my html is a snippet, so does not contain <html> or <body> tags. If you remove those tags from the .BodyHtmlText in your example above, you will get the same results as I do.
Is there a quick fix to this with a property setting? Or do i need to temporarily add these tags to my html string?
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 09 January 2015 at 9:50am | IP Logged
|
|
|
Will check this in detail and make a fix in future version if possible. In the meantime, you can indeed add html/body tag wrappers.
Regards,
Alex
|
Back to Top |
|
|
wenditaranto Newbie
Joined: 08 January 2015
Online Status: Offline Posts: 6
|
Posted: 09 January 2015 at 10:33am | IP Logged
|
|
|
Thank you, I have this part working.
I want to distribute this html with the cid references and embedded content to applications external to my own. I do not want to send the html out with file references pointing to my server. Is this possible?
When I call .BodyHtmlText, I see the html w/o the embedded content. And the only other way I know how to pull the html out of MIME is by using GetHtmlAndSaveRelatedFiles, and that obviously adds the files to disk.
Do I have any options here?
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 09 January 2015 at 11:03am | IP Logged
|
|
|
Sorry, I couldn't understand. If we weren't talking about ImportRelatedFiles before, I would recommend you using it. But it seems you need something different and I can't figure out what exactly.
Regards,
Alex
|
Back to Top |
|
|
wenditaranto Newbie
Joined: 08 January 2015
Online Status: Offline Posts: 6
|
Posted: 14 January 2015 at 7:07am | IP Logged
|
|
|
Hi Alex,
I am using ImportRelatedFiles to create the embedded content. Then i save this to disk. When I'm ready to pull this data out and use it outside of my application, i cannot determine how to get the html out of the MIME with the embedded content.
For example, when i look at a MIME object saved to disk, i see BodyHtmlText looks like:
<img alt="" src="cid:73b34c389a7f5edc11b6" />
this is missing the embedded content, but I see it as an attachment in the mailbee.net object. can i send this out to external app (as html string) without having to extract attachment to disk all while keeping the integrity of the html?
Here is my code:
Code:
Dim oMessage As New MailBee.Mime.MailMessage
oMessage.LoadMessage(System.Text.Encoding.ASCII.GetBytes(oValue))
Dim sPath As String = System.Web.HttpContext.Current.Server.MapPath("../Temp")
oMessage.Parser.WorkingFolder = sPath
GetFriendly = oMessage.GetHtmlAndSaveRelatedFiles()
'the mmr control requires relative web references, need to swap this out
'actually want to show the html with the cid and embedded content. waiting to hear back from mailbee.net
'GetFriendly = oMessage.BodyHtmlText
|
|
|
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 14 January 2015 at 7:13am | IP Logged
|
|
|
Please check Attachments collection and see if there's actually an attachment there with that .ContentID value. If it's there but it's not obtained properly, please provide us with the message via HelpDesk.
--
Regards,
Igor, AfterLogic Support
|
Back to Top |
|
|
wenditaranto Newbie
Joined: 08 January 2015
Online Status: Offline Posts: 6
|
Posted: 23 January 2015 at 1:32pm | IP Logged
|
|
|
i see the attachment, with the correct .ContentID. this is not the problem, as i can see the attachment within the body when i call GetHtmlAndSaveRelatedFiles. all of this is working as expected.
i'm trying to figure out how to "embed" this image into the html itself, as if i pasted an image into a rich text editor. i want to be able to take the html on it's own (w/o attachments or MIME) and use it elsewhere w/o dependence on image source paths.
is this doable with mailbee.net?
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 24 January 2015 at 3:04am | IP Logged
|
|
|
Well, this can be done. MailBee.NET itself does not have such functions built-in but it's possible to directly manipulate with HTML to inject them there. It's pretty pure HTML manipulation, not MIME or anything related to email. Perhaps, this can be enabled in your rich-text editor (how it outputs images in the resulting HTML) or you can post process that HTML and load images instead of links to them. After that you can simply load the resulting HTML into .BodyHtmlText.
Again, this is a kind of task specific to HTML processing, not email, and I can't go deep here. You can do some googling on embedding images with base64 patterns in HTML, it's pretty easy but you'll need to take care about browser compatibility and so on (for instance, different browsers have different limits on the maximum size of an image to be embedded and with IE8 any picture greater than 32K in size won't be displayed). So there are some external factors which may be or may be not important for you and it's up to you to decide if this works for you not.
Regards,
Alex
|
Back to Top |
|
|