vb.net发送带图片的电子邮件

关于发送带附件的电子邮件有很多话题,但我找不到我想要的东西

我的表单包含8个文本框和1个PictureBox我可以通过电子邮件发送所有文本框但不能发送PictureBox我尝试了很多代码

这是我的form.

这是我的代码

    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

点赞