[英]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.