If FileSys.GetFiles(ProjectPath & "Attachments\附件地址").count> 0 Then
output.Show("即将推送邮件")
Dim client As New System.Net.Mail.SmtpClient()
client.Host = "smtp.163.com" '//smtp服务器地址
client.Credentials = New System.Net.NetworkCredential("cn", "EV") '//发件人邮箱的用户和密码(授权码,并不是发件邮箱的密码)
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network '//将smtp的出站方式设为 Network
Dim message As New System.Net.Mail.MailMessage
message.From = new System.Net.Mail.MailAddress("cn@163.com")
message.To.Add("15@qq.com")'主送,多个邮件地址之间用半角逗号分开
message.Subject = "这是个测试邮件!" '//邮件标题
message.IsBodyHtml = True '; //邮件正文是否是HTML格式
Dim attach1 As new System.Net.Mail.Attachment( ProjectPath & "images\saoyisao.png", System.Net.Mime.MediaTypeNames.Image.Jpeg) '这里设置将图片显示在邮件中
message.Attachments.Add(attach1)
Dim pic1 As String = attach1.ContentId '设置ContentId
''对于html邮件,可以在正常邮件中写好内容,在查看html代码,复制到这里
Dim sb As New StringBuilder
sb.Append("Hello World<br>")
sb.Append("<img src=""cid:"& pic1 &"""/><br>") '将前面增加图片附件放入到邮件中直接显示,注意如果html代码中存在 " 请改成 ""
sb.Append("Hello China")
Dim content As String = sb.ToString '设置正文内容'
message.Body = content '//邮件正文
For Each File As String In FileSys.GetFiles(ProjectPath & "\Attachments\附件地址\")
Output.Show(File)
'For q As Integer = 0 To 1 '多个附件添加
Dim attachment As new System.Net.Mail.Attachment(File,System.Net.Mime.MediaTypeNames.Application.Octet) '//单个添加附件,第二个参数表示附件的文件类型,可以不用指定
attachment.name = FileSys.GetName(File)
attachment.nameEncoding = System.Text.Encoding.UTF8 '//设置附件显示名称的编码
message.Attachments.Add(attachment)
'Next
Next
'同步发送邮件
Try
client.Send(message) '//发送邮件,如果不返回异常则发送成功
msgbox("发送成功")
Catch ex As Exception
msgbox("发送失败:" & ex.message)
finally
message.Dispose()
End Try
For Each File As String In FileSys.GetFiles(ProjectPath & "\Attachments\附件地址\")
FileSys.DeleteFile(File,2,2)
Next
Else
output.Show("暂无附件可推送")
End If