I'm trying to retrieve HTML Class Names from a string variable created by responseText. I need to accomplish this using VBscript. Here is a sample of current code:
set http = createobject("Microsoft.XmlHttp")
http.open "GET","http://www.xxxxxxxxxxx.com/xxx-xxx?xxxxNumber=xxxxx",false
http.send ""
dim html : set html = CreateObject("HTMLFILE")
html.write http.responseText
dim trackdate : trackdate = html.getElementByClassName("tracking-history-date").[0].value
wscript.echo trackdate
I'm receiving the following error: Object doesn't support this property or mehtod: 'getElementByClassName'
I've run into this before. Although documented, the getElementsByClassName() method doesn't seem to actually be supported. Use something like this to work around the issue:
For Each el In html.getElementsByTagName("...")
If el.ClassName = "tracking-history-date" Then
Set trackdate = el
Exit For
End If
Next
Related
I would like to write a program that outputs the email from the website "https://10minutemail.net/" in a message box. Unfortunately, I can't find any code that allows me to store the ID in a variable.
I have tried this already without any results:
Dim email
email = ""
set webbrowser = createobject("internetexplorer.application")
webbrowser.statusbar = false
webbrowser.menubar = false
webbrowser.toolbar = false
webbrowser.visible = false
webbrowser.navigate("10minutemail.net")
email = webbrowser.document.all.item("fe_text")
wscript.echo(email)
The code runs with the Error: [unknown error][1].
[1]: https://i.stack.imgur.com/m1yHF.png
How to fix that?
Vbscript use HTML DOM with this method getElementById to get the particular element in a HTML code source page
So in your case, you can give a try with this code :
Option Explicit
Dim IE,Email_Value
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.navigate "https://10minutemail.net/"
Do While (IE.Busy)
WScript.Sleep 100
Loop
Email_Value = IE.document.getElementByID("fe_text").Value
wscript.echo(Email_Value)
IE.Quit()
This code is in MS Access (2010) VBA, using the Redemption library with Microsoft Outlook 2010.
I had this process working before, but we recently had a Citrix upgrade that I guess reset something in my Outlook and now the process no longer works.
I have a folder of .msg files which are basically pre-made email templates with all the proper formatting, images, text, etc.
This is what I was doing before:
Dim outlookApp As Object, namespace As Object
Dim oItem, MyItem
Set outlookApp = CreateObject("Outlook.Application")
Set namespace = outlookApp.GetNamespace("MAPI")
namespace.Logon
Set MyItem = outlookApp.CreateItemFromTemplate(path_to_dot_msg_file)
'And then there are many calls like this:
MyItem.HTMLBody = Replace(MyItem.HTMLBody, "Dear Person,", "Dear " & name)
'...
Set safeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = MyItem
safeItem.Item = oItem
'this next line displays the email, and as of this line, it looks correct
'safeItem.Display
'but as of this line, the issue occurs
safeItem.HTMLBody = "<p>This is an extra message that shows up before the .msg file</p>" & safeItem.HTMLBody
safeItem.Recipients.ResolveAll
safeItem.Send
Now when the email is sent, the .msg contents aren't present at all -- the only thing that shows up is the "extra message" that I prepended to the HTMLBody.
What do I need to change or update? Is this something I need to change in the code, or in my Outlook settings, etc?
Extra: body insertion:
Function insertStringBodyTag(htmlBody As String, stringToInsert As String)
Dim s As String
Dim i As Integer
s = htmlBody
i = InStr(1, s, "<body")
i = InStr(i, s, ">")
s = Left(s, i) & stringToInsert & Right(s, Len(s) - i)
insertStringBodyTag = s
End Function
'Called with safeItem.htmlBody = insertStringBodyTag(safeItem.htmlBody, prefix_string)
You cannot concatenate 2 HTML strings and expect a valid HTML string back - the two must be merged - find the position of the "<body"substring in the original HTML body, then find the positon of the following ">" (this way you take care of the body element with attributes), then insert your HTML string following that ">".
im trying to send an email from a VBScript, it will eventually be added into a currently working script as an else if (if this is possible).
im getting an error at line 23 character 32?
Dim outobj, mailobj
Dim strFileText
Dim objFileToRead
Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
strFileText = GetText("C:\test\test 2.txt")
With mailobj
.To = "user#user.com"
.Subject = "Testmail"
.Body = strFileText
.Display
End With
Set outobj = Nothing
Set mailobj = Nothing
End Sub
Function GetText(sFile as String) As String
Dim nSourceFile As Integer, sText As String
nSourceFile = FreeFile
Open sFile For Input As #nSourceFile
sText = Input$(LOF(1), 1)
Close
GetText = sText
End Function
what do i need to add to get line 23 to work and the script to finally do what i need it to, i have copied most of this script from elsewhere due to a sincere lack of VBscripting knowledge?
Take a look at the Using Automation to Send a Microsoft Outlook Message article. It provides a sample code and describes all the required steps for sending emails.
Try this: remove the GetText function entirely, and replace the line
strFileText = GetText("C:\test\test 2.txt")
with
Set fso = CreateObject("Scripting.FileSystemObject")
strFileText = fso.OpenTextFile("C:\test\test 2.txt").ReadAll
I am writing a nodejs application that will be sending html e-mail using emailjs. Basically I provide the html to send as a variable that I attach to the message.
Rather than build this variable using lots of string concatenation, I'd like to just render a view using express/ejs and save the contents to the variable.
So instead of doing:
messageHtml = '<html>'+ ....
message.attach({data: messageHtml, alternative: true});
I'd like to do something like:
messageHtml = render('emailTemplate.ejs', viewArgs);
message.attach({data: messageHtml, alternative: true});
Can this be done, and if so, how?!
Just require ejs directly and use as per the example, e.g simplified usage (without caching):
var ejs = require('ejs')
, fs = require('fs')
, str = fs.readFileSync(__dirname + '/emailTemplate.ejs', 'utf8');
var messageHtml = ejs.render(str, viewArgs);
message.attach({data: messageHtml, alternative: true});
I've got the code below, and I'm trying to set the from field to allow Unicode. Currently in my email client I get "??".
The subject line and any content shows the Unicode correctly. And looking at the MSDN, the property should be "urn:schemas:httpmail:from".
Anyone solved this issue?
Dim AC_EMAIL : AC_EMAIL = "test#test.com"
Dim AC_EMAIL_FROM : AC_EMAIL_FROM = "测试 <test#test.com>"
Dim strSubject : strSubject = """测试"" testing testing"
set oMessage = WScript.CreateObject("CDO.Message")
With oMessage
.BodyPart.charset = "utf-8" 'unicode-1-1-utf-8
.Fields("urn:schemas:httpmail:from") = AC_EMAIL_FROM
.Fields("urn:schemas:httpmail:to") = AC_EMAIL
.Fields("urn:schemas:httpmail:subject") = strSubject
.Fields.Update
.Send
End With
Set oMessage = Nothing
Found a work around. Not the prettiest, but it works. Basically I converted the string to Quoted-Printable.
.Fields("urn:schemas:httpmail:from") = "=?utf-8?Q?=E6=8F?= <test#test.com>"