如何在vb.net2005中向多个用户发送电子邮件? [英] how to sent email to multi users in vb.net2005?

查看:93
本文介绍了如何在vb.net2005中向多个用户发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在vb.net2005中向多个用户发送电子邮件?

how to sent email to multi users in vb.net2005?

推荐答案

我确定您可以在
I''m sure you could find the answer in one of these CP Articles.[^] What specifically are you having trouble with? What have you tried? Can you post the code that isn''t working?


除了 Kschuler 回答,我还指向两个链接链接2 [
In addition to Kschuler answer I am pointing two links Links1[^] and Links2[^] to go there and read thread to find out how to send email to multiusers


您好,
您可以使用此代码从所有邮件服务器发送电子邮件到

首先,您必须导入3个类
然后创建一个新的CLASS,并在上面放上此代码,或在SUB
中使用此代码. 之后您可以调用此类或子类并填写
您可以通过
分隔接收方(SendTo)电子邮件
例如(EmailSender("ir_digitalboy@yahoo.com","Morteza Shoja","you @ name.con,menad @ you.co,...",...

干得好.

最好的问候
Morteza Shoja

_______________________________________
导入System.Net
导入System.Net.Mail
导入System.Net.Mime
_______________________________________
私有子EmailSender(ByVal从作为字符串,ByVal显示名称作为字符串,ByVal发送至作为字符串,ByVal消息作为字符串,ByVal主题作为字符串,ByVal密码作为字符串,ByVal附加为字符串)
使用mailMessage作为新MailMessage(New MailAddress(SendTo),New MailAddress(SendTo))
mailMessage.Body =消息
mailMessage.Subject =主题
试试
将SmtpServer调暗为新的SmtpClient()
SmtpServer.Credentials =新的System.Net.NetworkCredential(发件人,密码)
SmtpServer.Port = 587

Dim MS()As String = From.ToString.Split("@")
昏暗的MailServer()作为字符串= MS(1).ToString.Split(.")
选择案例UCase(MailServer(0))
大小写为="GMAIL"
SmtpServer.Host ="smtp.gmail.com"
SmtpServer.EnableSsl = True
大小写为="YAHOO"
SmtpServer.Host ="smtp.mail.yahoo.com"
SmtpServer.EnableSsl = False
大小写为="AOL"
SmtpServer.Host ="smtp.aol.com"
SmtpServer.EnableSsl = False
大小写="LIVE"
SmtpServer.Credentials =新的System.Net.NetworkCredential(发件人,密码)
SmtpServer.Host ="smtp.live.com"
SmtpServer.EnableSsl = True
结束选择

mail =新MailMessage()
Dim addr()As String = SendTo.Split(,")
mail.From =新MailAddress(发件人,DisplayName,System.Text.Encoding.UTF8)
昏暗的我作为字节
对于i = 0要加长-1
mail.To.Add(addr(i))
接下来我
mail.Subject =主题
mail.Body =消息
mail.BodyEncoding = System.Text.Encoding.UTF7
如果为Attach.Length<> 0然后
mail.Attachments.Add(新附件(附件))
如果结束
mail.IsBodyHtml = True
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
mail.ReplyTo =新的MailAddress(SendTo)
SmtpServer.Send(邮件)
异常捕获
MessageBox.Show(例如,Message,"EMail",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
结束尝试
最终使用
结束Sub
Hello,
You can use this code to send email to from all mail servers

First you have to import 3 classes
Then create a new CLASSand put this code on it or use this code in a SUB
afte that you can call this class or sub and fill it
and you can seprate reciver (SendTo) email by ,

for example ( EmailSender("ir_digitalboy@yahoo.com","Morteza Shoja","you@name.con,menad@you.co,...",...

Good job.

Best Regards
Morteza Shoja

_______________________________________
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mime
_______________________________________
Private Sub EmailSender(ByVal From As String, ByVal DisplayName As String, ByVal SendTo As String, ByVal Message As String, ByVal Subject As String, ByVal Password As String, ByVal Attach As String)
Using mailMessage As New MailMessage(New MailAddress(SendTo), New MailAddress(SendTo))
mailMessage.Body = Message
mailMessage.Subject = Subject
Try
Dim SmtpServer As New SmtpClient()
SmtpServer.Credentials = New System.Net.NetworkCredential(From, Password)
SmtpServer.Port = 587

Dim MS() As String = From.ToString.Split("@")
Dim MailServer() As String = MS(1).ToString.Split(".")
Select Case UCase(MailServer(0))
Case Is = "GMAIL"
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
Case Is = "YAHOO"
SmtpServer.Host = "smtp.mail.yahoo.com"
SmtpServer.EnableSsl = False
Case Is = "AOL"
SmtpServer.Host = "smtp.aol.com"
SmtpServer.EnableSsl = False
Case Is = "LIVE"
SmtpServer.Credentials = New System.Net.NetworkCredential(From, Password)
SmtpServer.Host = "smtp.live.com"
SmtpServer.EnableSsl = True
End Select

mail = New MailMessage()
Dim addr() As String = SendTo.Split(",")
mail.From = New MailAddress(From, DisplayName, System.Text.Encoding.UTF8)
Dim i As Byte
For i = 0 To addr.Length - 1
mail.To.Add(addr(i))
Next i
mail.Subject = Subject
mail.Body = Message
mail.BodyEncoding = System.Text.Encoding.UTF7
If Attach.Length <> 0 Then
mail.Attachments.Add(New Attachment(Attach))
End If
mail.IsBodyHtml = True
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
mail.ReplyTo = New MailAddress(SendTo)
SmtpServer.Send(mail)
Catch ex As Exception
MessageBox.Show(ex.Message, "EMail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Using
End Sub


这篇关于如何在vb.net2005中向多个用户发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆