日期:2014-05-18 浏览次数:20484 次
'定义邮件对象 Dim MailMsg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage '定义邮件发送对象,括号中参数表示使用哪个邮件发送服务主机.获取或设置要用于发送电子邮件的 SMTP 中继邮件服务器的名称。 SmtpMail.SmtpServer = "10.16.14.144" '这个是我自己的主机IP,用主机的虚拟SMTP服务器做的 '定义邮件附件,必须使用如下格式。括号中参数是附件文件名。 Dim file_name() As String = Split(Me.assessory1.Text, ";") Dim i As Integer, mailatta() As String If Me.assessory1.Text <> "" Then For i = 0 To file_name.Length - 1 Dim accessory1 As System.Web.Mail.MailAttachment = New System.Web.Mail.MailAttachment("d:\microsoft SQL Server\mssql\datas\" & file_name(i).ToString) mailatta(i) = "d:\microsoft SQL Server\mssql\datas\" & accessory1.Filename Next i End If '定义发送邮件身份验证信息 'Dim IDCheck As New System.Net.NetworkCredential("邮箱用户名", "邮箱密码") If Me.txt_receive.Text = "" And Me.txt_copy.Text = "" And Me.txt_secret.Text = "" Then Response.Write("<script>alert('没有找到要将邮件发送给的人名')</script>") Exit Sub End If '发给谁 MailMsg.To = Me.txt_receive.Text '抄送给谁 MailMsg.Cc = Me.txt_copy.Text '秘密抄送给谁 MailMsg.Bcc = Me.txt_secret.Text '邮件主旨 MailMsg.Subject = Me.txt_title.Text '邮件正文 MailMsg.Body = Me.txt_content.Text '邮件正文格式 MailMsg.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8") MailMsg.BodyFormat = MailFormat.Html '加上附件 If Me.assessory1.Text <> "" Then For i = 0 To file_name.Length - 1 MailMsg.Attachments.Add(mailatta(i)) Next i End If '发件人邮箱 MailMsg.From = Session("user_email") '发送电子邮件。 SmtpMail.Send(MailMsg)