.mail Attachment Error

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
10 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

.mail Attachment Error
muttley1968
Hello again ones again my stupidity brings me to the smart people of the world i am trying to attack an
image of a picturebox to an email in vb.net but well it isnt working when done hopefully i will be able to
attack a screen print of a panel so it takes a pic of all the controlls in the panel as well and emails that
but anyway here is what i am getting

Image
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: .mail Attachment Error
comathi
You have to save the image, and then you can do this:
Code: Select all
Dim att as New System.Net.Mail.Attachment("image filename")
mail.Attachments.Add(att)
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: .mail Attachment Error
clanc789
muttley1968 wrote:
Hello again ones again my stupidity brings me to the smart people of the world i am trying to attack an
image of a picturebox to an email in vb.net but well it isnt working when done hopefully i will be able to
attack a screen print of a panel so it takes a pic of all the controlls in the panel as well and emails that
but anyway here is what i am getting
The attack an image is kinda funny, no hard feelings :D I think you ment attached. But to solve your problem: should it be imagelocation() (dont know if that exists?) or picturebox1.image() instead of picturebox1.image?
Practice makes perfect!

VIP since: 6-10-2011
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: .mail Attachment Error
muttley1968
hahaha i did mean atached yes sorry my bad and neither of them codes work as i cant save the image because its supposed to be autmated so unless there is a way to make it save its self to temp data or something i cant do that any ideas how i can fix this to just send the pictureboxes image over
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: .mail Attachment Error
mandai
There is no reason why the image has to be saved.

You can attach it from a stream with this:
Code: Select all
        Dim ms As MemoryStream = New MemoryStream()

        PictureBox1.Image.Save(ms, ImageFormat.Png)

        ms.Position = 0
        Dim a As Attachment = New Attachment(ms, "test.png")

        mail.Attachments.Add(a)
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: .mail Attachment Error
muttley1968
Thanks Mandai that work amazingly good but does anyone know how to take a screen shot of a panel and all its controls and then apply that image as the image of a picturebox :P
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: .mail Attachment Error
mandai
You could use this:
Code: Select all
Panel1.DrawToBitmap(PictureBox1.Image, New Rectangle(0, 0, Panel1.Width, Panel1.Height))
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: .mail Attachment Error
muttley1968
i tired to use that code and it said "Value cannot be null. Parameter name: bitmap" and wouldnt work
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: .mail Attachment Error
mandai
You can set the picturebox image variable with this:
Code: Select all
PictureBox1.Image = New Bitmap(Panel1.Width, Panel1.Height)
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: .mail Attachment Error
muttley1968
it doesnt work now it just does nothing know errors or anything but nothing happens
no errors no nothing
10 posts Page 1 of 1
Return to “Coding Help & Support”