-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendMail.vb
72 lines (62 loc) · 2.23 KB
/
SendMail.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Imports System
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mime
Imports System.Threading
Imports System.ComponentModel
Public Class KripaOpenSourceSentMail
Dim oSmtp As New SmtpClient
ReadOnly oSmtpPermission As New SmtpPermission(SmtpAccess.Connect)
Public Function SendMail(oHost As String, oPort As Integer, oSSL As Boolean,
oUser As String, oPass As String, oFrom As String, oTO() As String,
oCC() As String, oBCC() As String, oSub As String, oBody As String,
Fname() As String)
Try
oSmtp.Host = oHost
oSmtp.Credentials = New NetworkCredential(oUser, oPass)
oSmtp.Port = oPort
oSmtp.EnableSsl = True
Dim oSmtpMessage As New MailMessage With {
.From = New MailAddress(oFrom),
.Subject = oSub,
.Body = oBody
}
'CC Addresses
If oCC IsNot Nothing Then
Dim c As Integer
For c = 0 To oTO.Count - 1
oSmtpMessage.CC.Add(New MailAddress(oCC(c)))
Next
End If
'BCC Addresses
If oBCC IsNot Nothing Then
Dim b As Integer
For b = 0 To oTO.Count - 1
oSmtpMessage.Bcc.Add(New MailAddress(oBCC(b)))
Next
End If
'To Addresses
If oTO Is Nothing Then
MsgBox("Please Enter an Address to Send")
Else
Dim t As Integer
For t = 0 To oTO.Count - 1
oSmtpMessage.To.Add(New MailAddress(oTO(t)))
Next
End If
'Attachments
If Fname IsNot Nothing Then
Dim I As Integer
For I = 0 To Fname.Count - 1
oSmtpMessage.Attachments.Add(New Attachment(Fname(I)))
Next
End If
oSmtp.Send(oSmtpMessage)
MsgBox("Mail Send")
Catch ex As Exception
MsgBox("Mail Failed to send")
Return 1
End Try
Return 0
End Function
End Class