Imports Outlook
Public Class Email
Private mOutLookApp As Outlook.Application
Private mNameSpace As Outlook.NameSpace
Private mItem As Outlook.MailItem
Private strAttach As String
Public Event emailUpdate(ByVal status As String, ByVal code As Integer)
Public Event emailSubject(ByVal status As String, ByVal cod As Integer)
'mNameSpace.Logon(, , False, True)
Private mMailSubject As String
Private mMailTo As String
Private mMailAttachment As String
Public Sub New()
mOutLookApp = New Outlook.Application
mNameSpace = mOutLookApp.GetNamespace("MAPI")
End Sub
Public Property MailSubject() As String
Get
Return mMailSubject
End Get
Set(ByVal MailSubject As String)
mMailSubject = MailSubject
End Set
End Property
Public Property MailTo() As String
Get
Return MailTo
End Get
Set(ByVal MailTo As String)
mMailTo = MailTo
End Set
End Property
Public Property MailAttachment() As String
Get
Return MailAttachment
End Get
Set(ByVal MailAttachment As String)
mMailAttachment = MailAttachment
End Set
End Property
Public Function SendAttachment() As Boolean
If mMailAttachment <> "" Then
'send attachment
Return True
End If
End Function
Public Function SendMail() As Integer
Try
If mMailTo = "" Then
RaiseEvent emailUpdate("mail to address is blank", -125)
Return -1
Else
End If
If mMailSubject = "" Then
RaiseEvent emailSubject("mail subject is blank", -135)
Return -1
Else
End If
If mMailAttachment = "" Then
mItem.Send()
End If
Dim t As New System.Threading.Thread(AddressOf SendMailThread)
t.Start()
Return 1
Catch ex As System.Runtime.InteropServices.COMException
Return -1
End Try
End Function
Private Sub SendMailThread()
Try
mItem = mOutLookApp.CreateItem(0)
mItem.To = mMailTo
mItem.Subject = mMailSubject
If mItem.Attachments.Add(mMailAttachment) Is Nothing Then
mItem.Send()
System.Windows.Forms.MessageBox.Show("success, email sent")
Else
mItem.Attachments.Add(mMailAttachment)
mItem.Send()
System.Windows.Forms.MessageBox.Show("success, email and attachment sent")
End If
Catch ex As System.Runtime.InteropServices.COMException
MsgBox("error mail not sent")
End Try
End Sub
End Class