Skip to content
+1-888-319-3663

COMMUNITY FORUM

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. “info@eone.com” works well, then tried “info@eone.com , mick@eone.com” and “info@eone.com ; mick@eone.com” combinations, with and without spaces, and doesn’t send the email. Thank, Mick
lorren replied 7 years ago

Mick,

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

Thanks
Lorren

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
‘—————————————————————————————
Try
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 + “‘”

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

‘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()

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

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

End Try

‘Close the connection
myConn.Close()

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
Else
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 = “support@mac.com.au”
Dim receiver As String = “mac-Team-Finance@mac.com.au”
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 = “mailsrv.mac.com.au”
Dim hostPort As Integer = 25

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

‘Dim mapInterface As Integer = 1
‘—————————————————————————————

Try
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
‘Try
‘Dim attachment As New System.Net.Mail.Attachment(pathName)
‘Message.Attachments.Add(attachment)
‘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
SmtpClient.Send(Message)
Message.Dispose()
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

Answers
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

Lorren,

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

Thanks,

Mick

patrick answered 7 years ago

mick,

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.