Useage of the email function:
In order to send an email. Create a module the name doesn't matter. I called it "MyFunctions"
Add the sub routiene below:

Useage of the E-Mail Function:





The import state








Add the following:

Imports System.Data.SqlClient
Imports System.IO
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mime Module MyFunctions
    'The useage of this function is to cover all aspects of sending an email to users and for approvial.
    'Useage
    '................................................................................................
    'ConfirmEmail
    ' To be honest I am not sure what this variable is used for. So just set it as false
    '................................................................................................   
    'MySend2Email
    ' who are you sending an email too
    '................................................................................................
'MySubject
' The subject of the email
'................................................................................................
' MyMessageBody
' The message body. Include all links
'................................................................................................
'AdminApprove
' True of False does this email go to someone for so it can be approved
'................................................................................................
'DataTable
' If "AdminApprovial = True" the the admin users are stored in a data table. This is the name
' of the datatable
'................................................................................................
' ColumnName
'The Column in the datatable that holds all the admin users.
'................................................................................................
'................................................................................................
'................................................................................................
' Attachment
'This is the filename and path of an attacchment you want to add an attachment file in a pdf folder
'set ths variable as "PDF\OpenReccordsRequest.pdf"
'................................................................................................
'................................................................................................
'................................................................................................
'To just send an email with information the usage is
' SendMyEmai(False, "jamesw@bgadd.org", "this is my test email subject", "This is the body of the message", False, "", "")
'................................................................................................
'................................................................................................
'................................................................................................

Public Sub SendMyEmai(ConfirmEmail As Boolean, MySend2Email As String, MySubject As String, MyMessageBody As String,
AdminApprove As Boolean, DataTable As String, ColumnName As String, MyAttacchment As String)

Dim mailClient As New SmtpClient("smtp.office365.com")
mailClient.Port = 587
mailClient.EnableSsl = True
Dim cred As New System.Net.NetworkCredential("dontreply@bgadd.org", "Zot11256")
mailClient.Credentials = cred
Dim message As New MailMessage()
message.IsBodyHtml = True
message.From = New MailAddress("dontreply@bgadd.org", "")
message.Subject = MySubject
message.Subject = MySubject
message.Body = MyMessageBody
If MyAttacchment <> "" Then
If File.Exists(HttpContext.Current.Server.MapPath("~") & MyAttacchment) Then
Dim MyAttachment As New Attachment(HttpContext.Current.Server.MapPath("~") & MyAttacchment)
message.Attachments.Add(MyAttachment)
End If
End If

If AdminApprove = False Then
message.[To].Add(MySend2Email)
mailClient.Send(message)
Else
Dim con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString)
Dim queryString As String = "select " & ColumnName & " from " & DataTable
Dim ds_AdminEmail As New DataSet
Dim adapter As SqlDataAdapter
adapter = New SqlDataAdapter(queryString, con)
adapter.Fill(ds_AdminEmail, "AdminEmail")
If ds_AdminEmail.Tables("AdminEmail").Rows.Count = 0 Then
Exit Sub
End If
Dim xXx As Integer = 0
If ds_AdminEmail.Tables("AdminEmail").Rows.Count <> 0 Then
While xXx < ds_AdminEmail.Tables("AdminEmail").Rows.Count
message.[To].Add(ds_AdminEmail.Tables("AdminEmail").Rows(xXx).Item(0))
mailClient.Send(message)
xXx += 1
End While
End If
End If
End Sub

End Module