Skip to content


Script Email

Mick asked 7 years ago
I seem to be having a problem when using the script function to send an email to multiple addresses. I am using the restrictions, and set the email e.g. “” works well, then tried “ ,” and “ ;” combinations, with and without spaces, and doesn’t send the email. Thank, Mick
lorren replied 7 years ago


Can you paste the script here so we can look at it?


Mick replied 7 years ago

We added the GL Create/update account node to the GL Transaction MAP.

Add to the restriction:

‘———————————– CONFIGURATION ————————————-
Dim server As String = “MAC-YNAMIC”
Dim database As String = “DYNAMICS”
Dim user As String = “sa”
Dim password As String = “password
Dim myAccount As String = _GLACCNO
Dim mapInterface As Integer = 1
Dim myOwner As String = “”

‘Declare the connection string based on the configuration variables
Dim conString As New String(“Data Source=” & server & “;Initial Catalog=” & database & “;User=” & user & “;Password=” & password & “;”)
‘Define the query command to be run
Dim execute As String = “select ACTNUMST from mac_GL00105 where ACTNUMST='” + myAccount + “‘”

‘Define the SQL connection and open it
Dim myConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(conString)

‘Declare the SQL command as the query string
Dim myCmd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(execute, myConn)
‘Define the SQL Reader and execute it
Dim sqlReader As System.Data.SqlClient.SqlDataReader = myCmd.ExecuteReader()

‘Read the line
‘Store the account owner
myOwner = sqlReader(“ACTNUMST”).ToString()

‘If there is nothing to read, set the owner to ‘XX’
myOwner = “1”

End Try

‘Close the connection

Catch ex As Exception

System.Windows.Forms.MessageBox.Show(“An error has occurred in a calculated field: ” + ex.Message)
‘System.Windows.Forms.MessageBox.Show(conString + ” ” + execute)

End Try

If myOwner = “1” Then

‘If the account wasn’t found, it is added to the GlobalBCCAddress variable
GlobalBCCAddress = myAccount
GlobalBCCAddress = “”
End If

Catch ex As Exception
If (mapInterface = 1) Then
‘Messagebox.Show(ex.Message, “CheckAccountNumbers Script Error”)
End If
Return False
End Try

‘Return True
‘———————————– CONFIGURATION ————————————-
Dim sender As String = “”
Dim receiver As String = “”
Dim subject As String = “GL JRNL Import – New Account Added”
Dim body As String = GlobalBCCAddress + ” GL Account was missing, please check account is setup correctly”
Dim hostServer As String = “”
Dim hostPort As Integer = 25

Dim pathName As String =””
‘”C:Documents and SettingsAdministratorDesktopattachment.txt”

‘Dim mapInterface As Integer = 1

If GlobalBCCAddress <> “” Then
‘Declare the message object that will be sent
Dim Message As New System.Net.Mail.MailMessage()

‘Add all the necesary objects to the message
With Message
.To.Add(New System.Net.Mail.MailAddress(receiver))
.From = New System.Net.Mail.MailAddress(sender)
.Subject = subject
.Body = body
.IsBodyHtml = True
End With

‘Add the attachment, if one is specified
‘If Not String.IsNullOrEmpty(pathName) Then
‘Dim attachment As New System.Net.Mail.Attachment(pathName)
‘Catch e As Exception
‘ If (mapInterface = 1) Then
‘ System.Windows.Forms.MessageBox.Show(“There was an error with the attachment: ” & e.Message)
‘ End If
‘End Try
‘End If

‘Declare the e-mail client
Dim SmtpClient As New System.Net.Mail.SmtpClient

‘Specify the host server and port, along with the delivery method
SmtpClient.Host = hostServer
SmtpClient.Port = hostPort
SmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network

‘————————————– OPTIONAL —————————————
‘ If security issues arise, credentials can be specified here

‘Dim info As New System.Net.NetworkCredential(“username”, “password”)
‘SmtpClient.Credentials = info
‘SmtpClient.EnableSsl = True

‘Send the message
End If
Catch ex As Exception
If (mapInterface = 1) Then
‘Messagebox.Show(ex.Message, “SendEmailAttachment Script Error”)
End If
Return False
End Try

Return True

Best Answer
Mick answered 7 years ago
Lorren, Looks like it was just the GL Account appeared twice in the import file. I could just group on the Account Number to create one email. Thanks, Mick
Mick replied 7 years ago


We still couldn’t get the email to send to multiple addresses, if you could have a look a the code would be appreciated.



patrick answered 7 years ago


your problem is that the recipient is one "recipient", not a large string that contains multiple addresses.

you have to add them one at a time to the mail object.

With Message

.To.Add(New System.Net.Mail.MailAddress(receiver)) .To.Add(New System.Net.Mail.MailAddress(receiver2)) .From = New System.Net.Mail.MailAddress(sender)

Patrick eOne

If you would like to submit an answer or comment, please sign in to the eOne portal.