Showing results for 
Search instead for 
Did you mean: 

Sending Email from within Rulestream

Community Manager Community Manager
Community Manager

To send email using the SendEmail subroutine, place the following code in custom.VB.


    Public Sub SendEmail()


            Dim message As New System.Net.Mail.MailMessage("", "", "Subject", "BodyText")

            Dim emailClient As New System.Net.Mail.SmtpClient("")


            'use the next 3 lines if your smtp server needs authentication else comment them out

            Dim SMTPUserInfo As New System.Net.NetworkCredential("myself", "mypassword", "mydomain")

            emailClient.UseDefaultCredentials = False

            emailClient.Credentials = SMTPUserInfo


            'use the next 2 lines to attach any files else comment them

            Dim attachFile As New System.Net.Mail.Attachment("C:\Attachment.GIF")





        Catch ex As Exception

            MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub



Use the following code to send an Email from Exchange:




To use the signature you need to create a signature called Siemens (in this example). The email will be sent as HTML. If you don’t want HTML delete the signature section and change .HTMLBody to .Body


Public Sub SendMail(ByVal Subject As String, ByVal Bodytext As String, ByVal Recipient As String, Optional ByVal Attachment As String = "File as Attachment")



            '--- Check whether the Outlook process is running

            If Process.GetProcessesByName("outlook").Length > 0 Then

                '--- evrything is fine don't do anything ---


                '--- start Outlook  ---



            End If


            '--- initalize Outlook ---

            Dim objOutlook As Object

            Dim objOutlookMsg As Object

            Const cMailItem = 0


            '--- if needed please uncomment ---

            'Const cBCC = 3

            'Const cImportanceHigh = 1

            'Const cCC = 2

            Const cTo = 1


                                             '--- get Signature ---

                                             Dim appData As String = Environment.GetEnvironmentVariable("APPDATA")

                                             Clipboard.SetText(IO.File.ReadAllText(appData & "\Microsoft\Signatures\Siemens.htm", System.Text.Encoding.Default))

                                             Dim mySignature As IDataObject = Clipboard.GetDataObject()


            '--- create object ---

            objOutlook = CreateObject("Outlook.Application")

            objOutlookMsg = objOutlook.CreateItem(cMailItem)


            '--- create mail ---

            With objOutlookMsg

                Dim objOutlookRecip As Object = .Recipients.Add(Recipient)

                objOutlookRecip.type = cTo

                .Subject = Subject

                .HTMLBody = Bodytext & CType(mySignature.GetData(GetType(String)), String)

                'If Attachment <> "File as Attachment" Then .Attachments.add(Attachment)

                '.Importance = olImportanceHigh 'If needed please uncomment

                .Display() ' Display() shows mail, .Send() sends directly

            End With


            '--- destroy object ---

            objOutlookMsg = Nothing

            objOutlook = Nothing


        Catch ex As Exception


            '--- Catch error if Outlook is not installed ---




        End Try


    End Sub