如何使用vb.net中的默认电子邮件客户端发送带附件的电子邮件

时间:2016-09-27 07:03:58

标签: vb.net email-attachments email-client mapi

我想知道它是如何做到的。有可能吗?

这是我的简单代码:

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

我想在默认客户端加载之前在其中添加附件。不幸的是,我在网上找不到任何答案。你能提一些建议吗?非常感谢提前。

1 个答案:

答案 0 :(得分:0)

您需要调用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以供参考。

希望有所帮助