|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Public Function SendMail(ByVal strOrder As String, ByVal StrEmail As String) As Boolean
- If Len(StrEmail) = 0 Then
- MsgBox("E-mail address not found", MsgBoxStyle.Information)
- Return False
- End If
- Dim MailClient As New System.Net.Mail.SmtpClient
- MailClient.Host = "smtp.163.com"
- MailClient.UseDefaultCredentials = False
- MailClient.Credentials = New System.Net.NetworkCredential("*******", "*******")
- MailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
- Dim Message As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage("l********@163.com", StrEmail)
- Message.Subject = "订单邮件确认"
- Message.Body = Replace(strBody(), "@Order", strOrder)
- Message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312")
- Message.IsBodyHtml = True
- Message.Attachments.Add(New Net.Mail.Attachment(Application.StartupPath & "\youjian.doc")) ''''''''''''添加附件
- Try
- Application.DoEvents()
- MailClient.Send(Message)
- MsgBox("发送成功")
- Return True
- Catch ex As Exception
- MsgBox("发送失败" & " " & ex.ToString)
- Return False
- End Try
- End Function
- Private Function strBody() As String
- Dim StrPath As String, strIni As String
- StrPath = Application.StartupPath & "\mailbody.ini"
- Dim fileStream As FileStream = New FileStream(StrPath, FileMode.Open)
- Dim fileread As StreamReader = New StreamReader(fileStream, System.Text.Encoding.GetEncoding("gb2312"))
- strIni = fileread.ReadToEnd()
- fileread.Close()
- fileStream.Close()
- Return strIni
- End Function
复制代码
[ 本帖最后由 a371014988 于 2010-9-30 13:25 编辑 ] |
|