vb.net - How to send Image as email attachment using Restful service -
below vb.net code i'm using receive image jquery ajax call..
public function mailkpichart(byval img string) genericresponse(of boolean) implements ikpi.mailkpichart dim smtpserver new net.mail.smtpclient() smtpserver.credentials = new net.networkcredential("xyz@gmail.com", "password") smtpserver.port = 587 smtpserver.host = "smtp.gmail.com" smtpserver.enablessl = true dim blstatus boolean try dim mailmessage new mailmessage() mailmessage.from = new mailaddress("from@gmail.com", ".net devoloper") mailmessage.to.add(new mailaddress("to@gmail.com")) mailmessage.subject = "test mail" mailmessage.body = "hello world" dim imgstream new memorystream() dim image system.drawing.bitmap = getimagefrombase64(img) dim filename string = "sample image" image.save(imgstream, system.drawing.imaging.imageformat.png) mailmessage.attachments.add(new attachment(imgstream, filename, system.net.mime.mediatypenames.image.jpeg)) smtpserver.deliverymethod = smtpdeliverymethod.network smtpserver.send(mailmessage) blstatus = true return serviceutility.buildresponse(of boolean)(blstatus, string.empty, string.empty, 0) catch ex exception return serviceutility.buildresponse(of boolean)(false, "", ex.message, appconstants.errorseveritycodes.high) end try end function
and function i'm converting base64 string image
public function getimagefrombase64(byval uploadedimage string) image 'get temp image bytes, instead of loading disk 'data:image/gif;base64, 'this image single pixel (black) dim bytes byte() = convert.frombase64string(uploadedimage) dim image__1 image using ms new memorystream(bytes) ms.write(bytes, 0, bytes.length) image__1 = image.fromstream(ms) end using return image__1 end function
and when see gmail inbox c mail attachment dont see actual image i've sent..i c blank image
help needed
regards
i had same issue , solved adding following line before attaching stream message.
imgstream.position = 0
regards, jonathan.
Comments
Post a Comment