在字符串中设置定界符 [英] Set a delimiters in a string
本文介绍了在字符串中设置定界符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Protected Sub SendMail_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles SendMail.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("fiona@gmail.com", "donkeyboat")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress("fiona@gmail.com")
mail.To.Add("fionatyl@hotmail.com")
mail.Subject = "Test Mail"
mail.IsBodyHtml = True
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("Mail Send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
上面是我当前的代码.我想对发送邮件的行进行更改.现在,我只能将其发送给一位收件人.如何编辑它,以便可以将其发送给其他许多以'';''分隔的收件人?
需要紧急帮助.谢谢
Above is my current code. I would like to do changes for the line to send the mail to. right now i can only send it to one recipient. how do i edit it so that i can send it to many other recipients separated with '';'' ?
urgent help is needed. thank you
推荐答案
尝试一下:
Try this:
string addresses = "abc@123.com;def@123.com;ghi@123.com";
foreach(string address in addresses.split(';'))
mail.To.Add(address)
MailMessage.To
属性返回MailMessageCollection
,如此处http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.to [ ^ ].
MailMessageCollection
的Add method
接受string of mail addresses separated by comma character
,如此处 http://msdn.microsoft. com/en-us/library/ms144695.aspx [ ^ ]
因此,要将邮件发送到多个邮件地址,请使用Add method of To property of MailMessage object with the Addresses in a string separated by ,
,如下所示
TheMailMessage.To
property returns aMailMessageCollection
as explained here http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.to[^].
TheAdd method
ofMailMessageCollection
accepts astring of mail addresses separated by comma character
as explained here http://msdn.microsoft.com/en-us/library/ms144695.aspx[^]
Hence, to send mail to multiple mail addresses useAdd method of To property of MailMessage object with the Addresses in a string separated by ,
as shown below
mail.To.Add("add1@hotmail.com,add2@hotmail.com,add3@hotmail.com")
这篇关于在字符串中设置定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文