ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Best Script type to build an email body line by line

(1/2) > >>

questorfla:
This is something that might have other solutions but if it can be done in a single script it would be handy.  VBS PS Batch whatever.
the content is a list of hyperlinks that need to be emailed.  Currently I do it by building an RTF file which then has to be zipped to be attached to an email.

i have it all working but would like to remove the extra steps required at each end for zipping and unzipping as well as making each written hyperlink active when clicked.

I am now building the .rtf file line by line in a separate script and it would be helpful to instead read each line into the body of the email that is used to send it. 

Currently, i am using a VBS script to get to where i go now.  Once i get to the steps that open Outlook and begin the email, i would need to add the correct vbs code to read the hyperlinks from one location and paste them into the email body then go to the next line for the next hyperlink.

The end result would be a list of maybe 40 hyperlinks which the end of the VBS script adds the recipient's name and sends it on its way.

The code below works by me dropping the zipped file onto the VBS script on my desktop to initiate and send the email.

It works fine that way except for the zipping /unzipping, etc

Is there a way to add the proper code to create the content for the body at step "oEmailItem.BodyFormat = olFormatHTML"?

What would be the proper statement to add to the VBS to loop through a list if hyperlinks and write them to the email body?

Currently the first script i use echoes the variables to the .rtf file.  I tried loading the contents of the entire .rtf file to the email body but it loses all the layout and everything runs together.

Thanks for any ideas.  Note that i the code below i used "examples" for the recipient but the rest is pretty much working as is.



--- ---Option Explicit
Dim objArgs, OutApp, oNameSpace, oInbox, oEmailItem, olMailItem
Dim a, oAttachments, subjectStr, olFormatHTML
olMailItem = 0
olFormatHTML = 2
Set objArgs = WScript.Arguments 'gets paths of selected files
Set OutApp = CreateObject("Outlook.Application") 'opens Outlook
Set oEmailItem = OutApp.CreateItem(olMailItem) 'opens new email
oEmailItem.To = "recipient@email.com"
oEmailItem.cc = ""
For a = 0 to objArgs.Count - 1
Set oAttachments = oEmailItem.Attachments.Add(objArgs(a))
subjectStr = subjectStr & Right(objArgs(a),Len(objArgs(a))-(InStrRev(objArgs(a),"\"))) & ", " 'recreates the default Subject e.g. Emailing: file1.doc, file2.xls
Next
If subjectStr = "" then subjectStr = "No Subject "
oEmailItem.Subject = "Subject"
oEmailItem.BodyFormat = olFormatHTML
oEmailItem.Display
oEmailItem.Send

4wd:
What's the point in creating the RTF file in the first place (and why RTF for a list of links, plain text is easier)?
Where do the list of links that go into the RTF come from?

Sounds like a lot of needless double handling at the moment.

You could just create a HTML file with the links and use it as the body of the email like back here.

Shades:
Just make sure that when you decide to drop the whole RTF thing and make an HTML-based mail body, you keep the HTML layout as simple as possible. Forgo the use of CSS as much as you can, because if you think browsers on computers, tablets and/or smartphones can suck, you haven't had the "pleasure" of making HTML content look the same in mail clients.

Better use simple HTML v4.0 stuff.  The above isn't valid if you just create a file only with a set of links...but once that list gets spread around, there will soon be someone telling you to make something look visually pleasing, add the company logo, etc., etc. You'd think you had a headache till now?

I need to transport builds of from different versions of our software and was asked to make a dynamically generated mail message with logo, layout and all...in batch and send it (to be in line with the rest of the procedure). Serious levels of frustration getting things to look the same on multiple mail clients, browsers and devices, I now get completely why people use mail-list companies and their software to send visually pleasing mail messages.

For the sending part, I tried Blat, but had more success with CMail. Ah well, both are freeware.

questorfla:
thanks all.  :-[
I gotta remember to stop making posts a 2 am.  :huh:
After giving it more thought in the light of day, i realized that I was making life hard for myself.  The reason for the rtf is that the written text can become active URL's once they are selected and clicked whereas in a text file this does not happen.
if i could have "read" the contents of the file whether rtf or txt into the body of the email line by line so it would retain the proper formatting, this would have solved the problem as the email body is html.

However:  After giving it a lot of thought, I decided that the person i was doing this for was going to have to give up and just open the attached file itself and from there either copy the link to a browser or do with it as they may need to get where they want to go.

But.. at 2am .. sometimes things don't look the same.
I am also currently caring for two very ill Flu victims :( (wife and daughter)

Either way, i have dropped the idea of making life easier for this person.
 
My only glitch in the works now is that there is almost NO way to get Outlook to SEND the blasted email once composed except by use of the vbs script here which is one I configured a year or so ago.   It was designed to be a 'drag and drop' email app which it works great for.  You see a brief BLINK and the email is gone.

Unfortunately.  I need to tie all this to the nightly backup which is a batch script.  I can use 'ipm.note' to build the email in batch and it works great!
BUT it wont SEND it.
I can build the file in the batch then use the VBS to send it ..
But
so far i have been unable to reconfigure the vbs to use a specific file rather than working as designed to capture the files dropped onto the VBS script.
This is from a lack of knowing much about WSH i am sure.  The original VBS file was one I reconfigure for my needs at  the time.  And it still works perfect for what i needed as i use it every day to drag and drop all kinds text files or zip files etc that i need to email to myself.

If you happen to see how i can set it to send a specific file at "C:\lists\listname.rtf"  as the only attachment?  That would do the trick.

Once the backup runs, i can call that vbs to send the resulting list.rtf to the person that needs it.  and it would all happen "auto-magically" at 4 am every night when the backup ran without me doing anything.
So i can go back to taking care of the ill. :(

PS:  4WD  I think what I was doing back then was sending an image file?  And i think we did end up with a BLAT script to do it? I wil revisit that as soon as i get a few minutes to do so.  But if BLAT was how it worked it may not "fly" now with the new exchange server setup and al the security checks on email configurations.
But it might work.   And i will look at that option.
I just know for SURE if i can get the VBS to handle a single named file at a specific location that it will for 100% sure work.









 



4wd:
My only glitch in the works now is that there is almost NO way to get Outlook to SEND the blasted email once composed except by use of the vbs script here which is one I configured a year or so ago.   It was designed to be a 'drag and drop' email app which it works great for.  You see a brief BLINK and the email is gone.

...

so far i have been unable to reconfigure the vbs to use a specific file rather than working as designed to capture the files dropped onto the VBS script.-questorfla (March 10, 2017, 05:46 PM)
--- End quote ---

Powershell


--- Code: Text ---%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -sta -noprofile -executionpolicy bypass -Window Hidden -File "EmailArc.ps1" [email protected] somefile.rtf

I think what I was doing back then was sending an image file?
--- End quote ---

Yes but you might find that if you just write out a file with the links and call it links.html and then tell blat/cmail to use it as a HTML email body that it might be enough so that it gets interpreted as an email full of clickable links at the other end.

Otherwise, it's no big deal to write each link as <a href=http://some.link1.com>Link1</a> in a file and use that as the HTML body.

Navigation

[0] Message Index

[#] Next page

Go to full version