Jump to content
Software FX Community

Email Chart Image via C#


drphillips40

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...