本文介绍了将邮件发送给多个收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
美好的一天。我需要一个关于如何向多个收件人发送邮件的想法。我能够将它发送给单个收件人。邮件收件人列表将从我的SQL查询中获取,因此我将通过单击按钮发送这些邮件收件人。感谢是否有人会帮忙。
请在此处找到我的代码以发送邮件功能
Hi All,
Good day. I need an idea on how can I send mail to multiple recipient. I able to send it to single recipient. List of mail recipient will be getting from my sql query and thus I will send these mail recipient by a click of button. Appreciate if anyone would help.
Please find my code here for send mail function
Public Function sendEmailToUser(ByVal emailaddress As String(), ByVal title As String, ByVal contents As String, Optional ByVal html As Boolean = False, Optional ByVal Engineer As String = "") As Boolean
Dim email As MailMessage
Dim smtp As SmtpClient
Dim EmailCredentail As NetworkCredential
Dim sender As MailAddress
Dim replyTo As MailAddress
Dim strSQL As New StringBuilder
Dim ReplytoEmail As String = ConfigurationManager.AppSettings("Email").ToString
Dim ReplytoName As String = ConfigurationManager.AppSettings("SenderName").ToString
sender = New MailAddress(ConfigurationManager.AppSettings("Email").ToString, ConfigurationManager.AppSettings("SenderName").ToString)
smtp = New SmtpClient(ConfigurationManager.AppSettings("SMTP").ToString, CInt(ConfigurationManager.AppSettings("Port").ToString))
smtp.EnableSsl = CBool(ConfigurationManager.AppSettings("SSL").ToString)
EmailCredentail = New NetworkCredential(ConfigurationManager.AppSettings("EmailAccount").ToString, ConfigurationManager.AppSettings("EmailPassword").ToString, "")
smtp.UseDefaultCredentials = False
smtp.Credentials = EmailCredentail
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
email = New MailMessage()
email.Sender = sender
email.From = sender
replyTo = New MailAddress(ReplytoEmail, ReplytoName)
email.ReplyTo = replyTo
email.Subject = title
email.Body = contents
email.Headers.Add("Disposition-Notification-To", "[email protected]")
If html = True Then
email.IsBodyHtml = True
Else
email.IsBodyHtml = False
End If
For Each s As String In emailaddress
Try
email.To.Add(New MailAddress(s.Trim))
Catch ex As Exception
errorMessage(ex, "Error when add email address, may be email address wrong format.")
End Try
Next
Try
smtp.Send(email)
Return True
Catch ex As Exception
errorMessage(ex, "Fail to send email at function sendEmailToUser.")
Return False
End Try
Return False
End Function
推荐答案
这篇关于将邮件发送给多个收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!