简体   繁体   English

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

[英]How to send an email with attachment using default email client in vb.net

I am wondering if how it could be done. 我想知道是否可以做到。 Is it possible to do it? 有可能做到吗?

Here is my simple code: 这是我的简单代码:

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

I want to add an attachment inside of this before the default client loads. 我想在默认客户端加载之前在其中添加附件。 Unfortunately, i don't find any answers in the web. 不幸的是,我在网上找不到任何答案。 Can you give some advice? 你能给点建议吗? Thanks so much in advance. 非常感谢。

you need to call the MailMessage.Attachments(). 您需要调用MailMessage.Attachments()。 Here's the example code: 这是示例代码:

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)

Please see this for reference. 请参阅作为参考。

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM