I have been using spoolmail on localhost and have ...
# cfml-general
m
I have been using spoolmail on localhost and have a love/hate relationship with it when the email contains embedded images
<cfmailparam file="#variables.imgPath#icon-yt.png" contentid="iconyt" disposition="inline" />
Any tips on either, a) how to modify the display page, or b) an alternative to spoolmail that shows what the actual email looks like.
e
Log the entire generated email to file or database.
m
That's not the issue. I don't have any reason to save it. I want to View/Render it, and spoolmail does that just fine if your images are inline. If you embed, you get this. along with image placeholders and then below, the encoding for the images.
e
The viewer is working as expected. Mime Encoding is just that, if you want to view the decoded image you will need to do something else.
m
Are you talking about this SpoolMail... https://github.com/cfjedimaster/SpoolMail If so it is open source and hasn't been modified for most of a decade so you could modify it?
m
Exactly, which is what I think I originally asked for. Now that we are on the same page, any suggestions?
@Michael Schmidt That's the one, and yes I can modify it, if I had a place to start. Unless of course there is a modern alternative to it.
e
I gave you my suggestion, render the content to a page and you can view it Or you can find a mime decoder and manually paste MIME code into it, if that doesn't scream 1994, I don't know what does.
m
My guess is looking at this code... You could detect if it is is a Image then send out the base64 value into an img tag?
m
Ah ha, "Find a mime decoder" is something I can understand.
and that 1994 ref is why I asked for a modern replacement that could do the same thing on localhost
e
Its easier, just before your code sends the result, to dump it to a database or file and let your browser do the work. You dont even need to host the webpage, just render the html to a file and open the file in a modern browser. You would use cffile Mypath #emailUniquieID#.html or something very close and now you have what you need, something to go view the encoded email
m
So, you are saying it is as easy as taking myfile.cfmail, saving that to a database. creating a page that pulls that content in a cfoutput?
or cfdump?
or taking the result of this block of code and saving it to the DB to display
<cfif mail.type is "text">
<pre>
#mailbody#
</pre>
<cfelseif mail.type is "multipart">
#replace(activateURL(mail.plain,"_new"),"#chr(10)#","<br>","all")#
<hr>
#mail.html#
<cfelse>
#mailbody#
</cfif>
@Michael Schmidt All that will do is render the images in the bottom part of the display page and not render them inline in the displayed email.
m
well you know what it outputs when a file is supposed to be there render your images prior and do a replace in the text with rendered images...
e
ALl the code to generate your email, right before you submit the code to your email process run another bit of code to dump it to a file with a .htm extension or just render the result in page, and you can see what is happening.
m
Doing that right now..
@Michael Schmidt the problem is that the email is rendered in that block of code above
m
that isn't a problem so before that block of code happens get the attachments (probably just image attachments to make it easy) then store them in a Struct then do a replace on the rendered value with what is coming out. What does the pure HTML look like for the output and that will be the hints of what you should be replacing and utilizing...
m
@Evil Ware @Michael Schmidt what is output is the cid reference to the image. <img src="cid:iconquestion"> So it looks like the answer is going to be a regex of some sort with a replace and base64. Still hoping for a more modern solution before I dive off into this..
m
What are you using this viewer to do? Review unsent messages? Review Failed Messages? Or just in a dev environment?
In my isolated dev environment i have all emails go to mailhog.
m
its only in dev. And just to view the emails. Mostly just to make sure they are being addressed correctly and spoolmail is perfect for that, but lately I have been reformatting a lot of email templates and it would be nice to see them locally instead of uploading and sending to myself repeatedly - at least until I am relatively happy with the output
m
Yep this is where i would use mailhog for... https://github.com/mailhog/MailHog
m
a modern alternative to spoolmail? I'll give it a shot before I do the work in spoolmail. Thank You!
e
if its a dev enviroment just dump everything to a local mail server, and view it with any client you like 🙂
m
that's just it, no local mail server. Never really had a need for one.. I'm installing MailHog.
well, mailhog didn't provide a solution, it displays same as spoolmail does..
g
I use papercut. It sends all emails JUST to the local account machine acount. COmes with its own client for accessing mail. There is also mailtrap.io - which has a free teir if you're not sending more than (I think) 500 emails a month.
m
What do you mean by local account machine account?
g
Sorry - my mind works a lot faster than my fingers! It is a mailserver on your local machine - and reghardless of TO address sends everything to the same "local" email account - the papercut application comes with a client that reads all the emails. It is for developers so has tabs for RAW / MailHeaders / etc - so you can "get into" the details of an email - if thats needed. I just use it to send all my exception emails to - while developing locally.
m
@gavinbaumanis Have you used Mailtrap? I don't want to modify the address info, but I also don't want to send test emails to real people - did that once at NASA and lets just say it wasn't a good day/week/month
Pretty sure this isn't the PaperCut you are referring to.. https://www.papercut.com/
m
g
I used mailtrap before swapping to papercut - I kept going over the free limit and didnt want to pay for it anymore. - but same/same - it just has a web client for accessing the mail. If you're worried about "dev" mail going out to "real" people (other than devs of course) - you can specify mail setting on the fly... So you can do something like (pseudo-code) if(cgi.host CONTAINS "localhost") { Set all mail settings to papercut/mailtrp.io } And just put that in your email "service" (if you have one) - or directly into the code where you are sending yuour email - if you dont have a "central" email service/function.
m
ok, this is the crux of the problem, and papercut sounds very similar to MailHog. When using this for images in cfmail, html type
<cfmailparam file="#variables.imgPath#icon-yt.png" contentid="iconyt" disposition="inline" />
What ends up in the .cfmail is this
<img src="cid:iconyt">
Which, of course, can't be rendered in the browser. Even MailHog used the cid: as the src for the image tag. These emails, sent to outlook, gmail, etc render just fine, though looking at gmail, google uses some offline method to render the image, so I expect that is also in outlook and other email clients. When you look in the .cfmail file, thisis how they are handled.
file:  E:\webroot\sbnew\image\l\email\icon-yt.png
filename:  icon-yt.png
file-type:  application/octet-stream; name=icon-yt.png
file-disposition:  inline
file-id:  <iconyt>
remove:  false
@gavinbaumanis PaperCut is the solution to my problem. Not only is it a one-click install, it renders the embedded images like it should! Thanks for the tip! Now to work on building up my trust that it won't relay anything off my dev box 🙃
👍 1
👍🏼 1
🎉 1
z
I recommend always using a unique cid (i.e. include a guid), the spec is vague and i once had a problem with stupid apple mail showing the wrong attachments from other emails due to generic cids!
m
I haven't run into that before and I switched to using CID 5+ years ago, but its an easy tweak. Thanks for the heads up!