簡體   English   中英

vb.net發送帶圖片的電子郵件

[英]vb.net send email with image

有很多關於發送帶附件的電子郵件的話題,但我找不到我正在尋找的表格包含8個文本框和1個PictureBox我可以通過電子郵件發送所有文本框但是我不會發送PictureBox我嘗試了很多代碼

這是我的表格

這是我的代碼

    Dim MyMessage As New MailMessage
    Try
        MyMessage.From = New MailAddress("x@gmail.com")

        MyMessage.To.Add("x@gmail.com")

        MyMessage.Subject = "Data"

        MyMessage.Body = Label1.Text + "  =  " + IDTextBox.Text + Environment.NewLine + Label2.Text + "  =  " + ناوی_سیانی_کارمەندTextBox.Text + Environment.NewLine + Label3.Text + "  =  " + ساڵی_لە__دایک_بوونTextBox.Text + Environment.NewLine + Label4.Text + "  =  " + شوێنی_دانیشتنTextBox.Text + Environment.NewLine + Label5.Text + "  =  " + گروپی_خوێنTextBox.Text + Environment.NewLine + Label6.Text + "  =  " + ناو_نیشانی_کار_لە_کۆمپانیاTextBox.Text + Environment.NewLine + Label7.Text + "  =  " + ژمارەی_مۆبایلTextBox.Text + Environment.NewLine + Label8.Text + "  =  " + شوێنی_کارTextBox.Text

        Dim SMTP As New SmtpClient("smtp.gmail.com")
        SMTP.Port = 587
        SMTP.EnableSsl = True
        SMTP.Credentials = New System.Net.NetworkCredential("x@gmail.com", "x")
        SMTP.Send(MyMessage)
        MsgBox("your message Has been sent successfully")
    Catch ex As Exception

    End Try

如果你能幫助我,我會很高興:)

你試過這個嗎。你可以使用LinkedResource和AlternatiView。

string path = Filelocation; // as you are using picture box,give the location from where the image is loading into picture box. 

LinkedResource imageLink = new LinkedResource(path);
imageLink.ContentId = "myImage";
AlternateView altView = AlternateView.CreateAlternateViewFromString(
  "<html><body><img src=cid:myImage/>" + 
  "<br></body></html>" + strMailContent, 
  null, MediaTypeNames.Text.Html);
altView.LinkedResources.Add(imageLink);

//now append it to the body of the mail
msg.AlternateViews.Add(altView);
msg.IsBodyHtml = true;

或者你可以用HtmlBody發送它這里是參考: http ://vba-useful.blogspot.fr/2014/01/send-html-email-with-embedded-images.html

您需要添加圖片文件的目錄或您擁有的任何文件,並將其作為附件添加到您的郵件中,如下所示...

Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment(FilePath)
MyMessage.Attachments.Add(attachment)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM