1

I need to send an email that contains a pie chart in the body of the email.

The Pie chart that is being included in the email body should have 25% of it filled.

So far i have sorted the email code. Here's the code.

  • This is a VB forms application.

    Try
        Dim Smtp As New SmtpClient
        Dim em As New MailMessage()
        Smtp.UseDefaultCredentials = False
        Smtp.Credentials = New Net.NetworkCredential("xx@gmail.com", "xxxxxx")
        Smtp.Port = 587
        Smtp.EnableSsl = True
        Smtp.Host = "smtp.gmail.com"
    
        em= New MailMessage()
        em.From = New MailAddress("xx@gmail.com")
        em.To.Add("y@y.com")
        em.Subject = "Pie Chart attached to email body"
        em.IsBodyHtml = True
        em.Body = "I have to attach a Pie chart that is 25% of it filled"
    
    
        Smtp.Send(em)
    
    
    Catch error_t As Exception
        MsgBox(error_t.ToString)
    End Try
    
Junaith
  • 3,298
  • 24
  • 34
Sharon Watinsan
  • 9,620
  • 31
  • 96
  • 140

1 Answers1

1

One way of doing this is to save the Chart image in local filesystem and attach it in the mail as inline attachment and keeping the body as html. See this SO question for more information.

chart1.SaveImage(fileName, ImageFormat.Jpeg);

// attach the saved image file.
Dim data As New Attachment(fileName, MediaTypeNames.Application.Octet);
em.Attachments.Add(data);
Community
  • 1
  • 1
Junaith
  • 3,298
  • 24
  • 34
  • How do i generate the Pie chart and save in Local file-system ? – Sharon Watinsan Mar 09 '14 at 05:16
  • @sharonHwk - I thought you already had the chart. If you haven't worked with MS Chart then go through this nice [article](http://www.codeproject.com/Articles/65803/A-Guide-to-using-MSChart-for-NET) and its example project. – Junaith Mar 09 '14 at 05:20