VB.NET mit hMailServer
VB.NET mit hMailServer
Hello,
we have been using hMailServer for more than 10 years to send measurement reports as html files to workstations.
This works very well. We are very satisfied.
Now we want to use scripting.
To my understanding: it is all written in a vbs file (different functions) and then retrieved depending on the rule needed function?Is it scripting only via vbs or also via VB.NET?
We need to automate a workflow. Customer sends name of file in message body - file is searched in specific directory and returned.
Can anyone give some examples on this or where else can I look?
Thanks a lot
Translated with [link removed] (free version)
we have been using hMailServer for more than 10 years to send measurement reports as html files to workstations.
This works very well. We are very satisfied.
Now we want to use scripting.
To my understanding: it is all written in a vbs file (different functions) and then retrieved depending on the rule needed function?Is it scripting only via vbs or also via VB.NET?
We need to automate a workflow. Customer sends name of file in message body - file is searched in specific directory and returned.
Can anyone give some examples on this or where else can I look?
Thanks a lot
Translated with [link removed] (free version)
Re: VB.NET mit hMailServer
Ok,
I'm starting to understand how it works, I wrote small vbs script to send a mail when an event occurs. (subject = "text")
If I run script not with hMS - is executed without problems, if script runs via hMS - then comes error message (logfile):
it is quite simple mail dispatch from vbs:
Why does error message come?
And 2 question -how can I read text with VBS body message and write to a variable?
Thanks a lot
I'm starting to understand how it works, I wrote small vbs script to send a mail when an event occurs. (subject = "text")
If I run script not with hMS - is executed without problems, if script runs via hMS - then comes error message (logfile):
Code: Select all
"Script Error: Source: Laufzeitfehler in Microsoft VBScript - Error: 800A01C2 - Description: Falsche Anzahl an Argumenten oder ungültige Eigenschaftszuweisung: 'Protokoll' - Line: 63 Column: 0 - Code: (null)"
Code: Select all
Sub Protokoll()
' Send Email without Installing the SMTP Service
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "send@pc.lokal"
objEmail.To = "ku@pc.lokal"
objEmail.Subject = "Testmail"
objEmail.Textbody = "Hier ist Data"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.2.100.003"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Your UserID on the SMTP server
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "send@pc.lokal"
'Your password on the SMTP server
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub
And 2 question -how can I read text with VBS body message and write to a variable?
Thanks a lot
Re: VB.NET mit hMailServer
https://www.hmailserver.com/documentati ... ssage_send
Here is an example of using hmailserver api to send a message. This can be used within eventhandlers.vbs and called by rule or triggered at one of hmailserver's events.
Here is an example of using hmailserver api to send a message. This can be used within eventhandlers.vbs and called by rule or triggered at one of hmailserver's events.
Re: VB.NET mit hMailServer
This is, SorenR's, our resident guru's, lookup match function.
I got the RegEx for file path from here: https://stackoverflow.com/questions/641 ... xe#6416209
No guarantees or warranties. Especially since I'm doing this from my mobile.
But it should at least point you in the right direction.
oMessage.Body is plain text body.
oMessage.HTMLBody is html.
Code: Select all
Function oLookup(strRegEx, strMatch, bGlobal)
If strRegEx = "" Then strRegEx = StrReverse(strMatch)
With CreateObject("VBScript.RegExp")
.Pattern = strRegEx
.Global = bGlobal
.MultiLine = True
.IgnoreCase = True
Set oLookup = .Execute(strMatch)
End With
End Function
strRegEx = "((?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+)"
Set Matches = oLookup( strRegEx, oMessage.Body, False )
For Each Match In Matches
o_filename = Match.Value
Next
No guarantees or warranties. Especially since I'm doing this from my mobile.

oMessage.Body is plain text body.
oMessage.HTMLBody is html.
Re: VB.NET mit hMailServer
I don't know what I'm doing wrong - I copied 1:1 to eventhandlers.vbspalinka wrote: ↑2021-02-17 14:49https://www.hmailserver.com/documentati ... ssage_send
Here is an example of using hmailserver api to send a message. This can be used within eventhandlers.vbs and called by rule or triggered at one of hmailserver's events.
my settings in - does not run
but always comes error in the logfile:
Code: Select all
"ERROR" 14296 "2021-02-17 15:04:00.819" "Script Error: Source: Laufzeitfehler in Microsoft VBScript - Error: 800A01C2 - Description: Falsche Anzahl an Argumenten oder ungültige Eigenschaftszuweisung: 'Senden' - Line: 13 Column: 0 - Code: (null)"
Code: Select all
Sub Senden()
dim oMessage
Set oMessage = CreateObject("hMailServer.Message")
oMessage.From = "Me <sender@domain.de>"
oMessage.FromAddress = "sender@domain.de"
oMessage.Subject = "Hi"
oMessage.AddRecipient "empfang@pc.local"
oMessage.Body = "This is the contents of the email."
oMessage.Save
End Sub
Re: VB.NET mit hMailServer
AddRecipient requires 2 arguments: name and address, so change that line to:deavik wrote: ↑2021-02-17 16:06I don't know what I'm doing wrong - I copied 1:1 to eventhandlers.vbs
my settings in - does not run
but always comes error in the logfile:
line 13 does not existCode: Select all
"ERROR" 14296 "2021-02-17 15:04:00.819" "Script Error: Source: Laufzeitfehler in Microsoft VBScript - Error: 800A01C2 - Description: Falsche Anzahl an Argumenten oder ungültige Eigenschaftszuweisung: 'Senden' - Line: 13 Column: 0 - Code: (null)"
Code: Select all
Sub Senden() dim oMessage Set oMessage = CreateObject("hMailServer.Message") oMessage.From = "Me <sender@domain.de>" oMessage.FromAddress = "sender@domain.de" oMessage.Subject = "Hi" oMessage.AddRecipient "empfang@pc.local" oMessage.Body = "This is the contents of the email." oMessage.Save End Sub
Code: Select all
oMessage.AddRecipient "empfang@pc.local", "empfang@pc.local"
Re: VB.NET mit hMailServer
Hmmm... This regex is more difficult than appears. Here's the best I could come up with:
https://regex101.com/r/u0AFJ3/1
The problem is that the string to find is in the email body, so its surrounded by other stuff. In this version, no spaces are allowed in the file name, but spaces are allowed in the path.
It will pick up C:\Program Files\filename.ext but not C:\Program Files\file name.ext
Also, there could be false positives with this so it should be tested thoroughly before putting it into use.
Code: Select all
([a-zA-Z]\:\\|\\\\)([\w\s\.]+\\)*(\w+(\.\w+)?)
The problem is that the string to find is in the email body, so its surrounded by other stuff. In this version, no spaces are allowed in the file name, but spaces are allowed in the path.
It will pick up C:\Program Files\filename.ext but not C:\Program Files\file name.ext
Also, there could be false positives with this so it should be tested thoroughly before putting it into use.
Re: VB.NET mit hMailServer
I will consider all suggestions.
I have to do other projects unfortunately, that because of I come later to it and will report.
Thank you!
I have to do other projects unfortunately, that because of I come later to it and will report.
Thank you!
Re: VB.NET mit hMailServer
"oMessage" is a reserved word.
You CAN use it but eventually you will need it for something else
Also, there is NO built in Shell object (WShell) in the script engine that hMailServer is using. You will have to declare it yourself.
Check the scripting section of the forum, there are hundreds of examples.
You CAN use it but eventually you will need it for something else

Also, there is NO built in Shell object (WShell) in the script engine that hMailServer is using. You will have to declare it yourself.
Check the scripting section of the forum, there are hundreds of examples.
SørenR.
Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.
Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.