流男@水孩

没有人可以像你,在我的感觉里....

Sending Multiple Emails At Once

Just like setting up emailing from a form, in general, is not difficult, neither is sending emails to multiple people at the same time. First, we need to dimension a variable called 'MyVar': to hold all the email addresses in a string:
Dim MyVar as String
In inline coding, this would be placed inside the script tag, but outside any Sub or Function.

Next we need to set up the BCC field, grabbing all the emails from a database field called (surprise!) 'email':

Dim MySQL as string = "Select email from yourTableName"
Dim MyConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("UrAppString"))
Dim objDR as SQLDataReader
Dim Cmd as New SQLCommand(MySQL, MyConn)
MyConn.Open()
objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
MyVar=""
While objDR.Read()
	MyVar+=objDR("email")& ";"
End While
MyVar=MyVar.substring(0,(MyVar.Length-1))
The last line merely removes the semi-colon from the end that will naturally be placed there due to the line inside the While section.

You might want to check out another Tutorial here, called 'Emailing Form Results'. It goes over much of this next section also.

Dim objEmail as New MailMessage
objEmail.To="News@YourDomain.com"
objEmail.FROM="You@YourDomain.com"
objEmail.BCC=MyVar
objEmail.SUBJECT="This is my Subject"
objEmail.Body="Put text or a variable which represents the text - here"
objEmail.BodyFormat = MailFormat.Text
SmtpMail.SmtpServer ="mail.YourDomain.com"
SmtpMail.Send(objEmail)
The main sections that needs addressing here are the BCC field, the BODY field, and the TO field. For most, the TO field will be fairly trivial. You don't need any of the people in the email addresses for this one. I usually use a mail back to me, in order to be sure the email actually went out. In the BCC field, you see that the list of emails in the 'MyVar' variable goes here, without double quotes surrounding it, since it's a variable and not an explicit email address. The same goes for the BODY section. If you wanted to define a section of text, and assign it to a variable, before this block of code, then, you would merely put the variable name there, without double quotes. Naturally, the SMTP server is important, since that's the mail server which you assign to send the emails out.

Hopefully, this takes a little mystery out of the whole 'sending multiple emails at the same time' scenario.

阅读更多
个人分类: WEBFORM
想对作者说点什么? 我来说一句

Best Practices for Performance

2015年09月10日 2.89MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭