drphillips40 Posted November 2, 2007 Report Share Posted November 2, 2007 Afternoon, I am trying to figure out a way to automatically email a copy of the chart image by a simple click of a button. If this is possible then the user can send e-mails without having to click the copy to clipboard, select bitmap, click the OK on the confirmation message box, then invoke their e-mail client and paste the image. All the email stuff is setup, just need to figure out how to get the selected chart image into the e-mail. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> Thanks, Dave Quote Link to comment Share on other sites More sharing options...
Frank Posted November 2, 2007 Report Share Posted November 2, 2007 I don't know how to add an image to an e-mail, however to obtain and image form the chart you can do: MemoryStream ms = new MemoryStream(); chart.Export(FileFormat.Bitmap,ms); ms.Position = 0; // Rewind Image img = Image.FromStream(ms,false,false); Quote Link to comment Share on other sites More sharing options...
drphillips40 Posted November 2, 2007 Author Report Share Posted November 2, 2007 Frank, Thanks - I'll work on getting the image to at least an e-mail attachement and let you knwo how it went. Dave Quote Link to comment Share on other sites More sharing options...
maximop Posted November 2, 2007 Report Share Posted November 2, 2007 As Frank mentioned, you can get the chart image by exporting it to a memory stream; you can then make use of the MailMessage class of the System.Net.Mail namespace to create a new e-mail message. You will need to export the chart to the desired file format, and specify the mime type for such format when creating the attach object. You can follow the code snippet below for an idea of what you need to do: MemoryStream ms = new MemoryStream(); Chart1.Export(FileFormat.Jpeg, ms); ms.Position = 0; System.Net.Mime.ContentType type = new ContentType("image/jpeg"); Attachment attach = new Attachment(ms, type); MailAddress address1 = new MailAddress("From"); MailAddress address2 = new MailAddress("To"); MailMessage mail = new MailMessage(address1, address2); mail.Subject = "This is a ChartFX test"; mail.Body = "This is a test..."; mail.Attachments.Add(attach); SmtpClient client = new SmtpClient();client.Host = "Your mail server"; client.Send(mail); Please note that per the security settings on my machine, this worked as expected. Also, you need to specify the mail server used for sending e-mail messages in this manner. Quote Link to comment Share on other sites More sharing options...
drphillips40 Posted November 5, 2007 Author Report Share Posted November 5, 2007 maximop, Thanks for the info. I almost had it but was using only one image stream but couldn't get it too work. Using two works just fine. Thanks for the assistance. Dave Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.