VB.NET控制outlook发邮件及附件

Imports Microsoft.Office.Interop.Outlook

Public Class Form1

    Dim person As String
    Dim theme As String
    Dim mailText As String
    Dim outObj As New Application
    Dim item As MailItem

    Private Sub sendMail(ByRef person As String, ByRef theme As String, ByRef mailText As String)
        item = outObj.CreateItem(0)
        '设定收件人地址
        item.To = person
        '设定邮件主题
        item.Subject = theme
        '设定邮件内容
        item.Body = mailText
        '设定添附文件
        item.Attachments.Add("D:xxx.xlsx")
        '发送
        item.Send()
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Call sendMail(TextBox1.Text, TextBox1.Text, RichTextBox1.Text)
    End Sub
End Class

 

你可能感兴趣的:(VB.NET)