我有一个发送电子邮件的功能,但是我无法在同一表格的子广告中调用它。
Imports System.Net.Mail
Public Function SendEmail(EmailBody As String,
EmailSubject As String, EmailTo As String,
AttachmentPath As String, EmailAsHTML As Boolean)
Dim Mail As New MailMessage
Try
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("[your gmail address@gmail.com]", "[the associated password]")
SMTP.Port = 587
Mail.From = New MailAddress("""[Friendly Name]"" <[your gmail address@gmail.com>")
'Split Multiple Addresses
If EmailTo.Contains(";") Then
For Each EmailAddress In EmailTo.Split(";")
Mail.To.Add(Trim(EmailAddress))
Next
Else
Mail.To.Add(Trim(EmailTo))
End If
Mail.Subject = EmailSubject
Mail.Body = EmailBody
If AttachmentPath <> "" Then Mail.Attachments.Add(New Mail.Attachment(AttachmentPath))
Mail.IsBodyHtml = EmailAsHTML
SMTP.Send(Mail)
'Clear Mail Object
Mail.Dispose()
'Function Return
Return True
Catch ex As Exception
'Function Return
Return False
End Try
End Function
有什么正确的代码可以调用这个子的任何建议吗?!