如何使用vb.net中的默认电子邮件客户端发送带附件的电子邮件
问题描述:
我在想如何才能做到。可以做到吗?如何使用vb.net中的默认电子邮件客户端发送带附件的电子邮件
这里是我的简单的代码:
Try
MsgBox("Please wait this may takes time to load", vbInformation, "Mailing System")
System.Diagnostics.Process.Start("mailto:" & txtEmailadd.Text)
Catch ex As Exception
MsgBox(ex.Message & " Having some technical difficulties, kindly check if the email textbox has data in it", vbCritical, "System Advisory")
End Try
我想要的默认客户端负载之前增加的这里面的附件。不幸的是,我在网上找不到任何答案。你能提出一些建议吗?非常感谢提前。
答
您需要调用MailMessage.Attachments()。以下是示例代码:
Dim MailMsg as New MailMessage
Dim loAttachment As Attachment = Nothing
Dim ls_email_attach as String
Dim server as String
ls_email_attach = "attach.xls"
server = "Mail server info"
//add the attachment
If Not ls_email_attach.Trim = "" Then
loAttachment = New Attachment(ls_email_attach)
loMailMsg.Attachments.Add(loAttachment)
End If
//send the email
MailMsg = New SmtpClient(server)
MailMsg.Send(loMailMsg)
请参阅this以供参考。
希望它有帮助
嗨,谢谢你的回复。我会试试这件事。 –