I’m experimenting on VB.NET Email Sending with Attached Imaging. The image is automatically captured from a Form. However, some of the labels that are dynamically loaded through data fetched from other Forms, are corrupted when I view the email. Any idea how?
I tried using CopyFromScreen, but that only copies from part of the screen where the screen halves. I also tried adding delays through thread sleep but it didn’t work.
Dim mail As New MailMessage()
Dim smtpServer As New SmtpClient("smtp.gmail.com")
mail.From = New MailAddress("[email protected]")
mail.To.Add("[email protected]")
mail.Subject = "Sales Invoice"
Using screenshot As New Bitmap(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
Me.DrawToBitmap(screenshot, Me.ClientRectangle)
Using memoryStream As New MemoryStream()
screenshot.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg)
memoryStream.Position = 0
Dim imageAttachment As New Attachment(memoryStream, "PrintedInvoice-SALESNO_" + frmManageSalesV2.lblBillingID.Text + "-.jpeg")
mail.Attachments.Add(imageAttachment)
smtpServer.Port = 587
smtpServer.Credentials = New System.Net.NetworkCredential("[email protected]", "my-password")
smtpServer.EnableSsl = True
smtpServer.Send(mail)
End Using
End Using
This is what I’m getting at my email:
Corrupted Labels
But for my designer, this is what should be showing up:
Expected Result of my Email
The printing works fine, in that when I save it as PDF the labels are saved properly.
Reirou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6