Sending email

Hi all

Need code that enable me to send report as email attachment without using fastreport preview control wizard and filling dialog form requested data


Thanks

Comments

  • edited April 2017
    sending email is a long running process and you dont want to block the UI, use background thread.
    using System.Threading.Tasks;
    using System.Net;
    using System.Net.Mail;
    
    TaskScheduler ts = TaskScheduler.FromCurrentSynchronizationContext();
    Task.Run(() =>
    {
        using (SmtpClient smtp = new SmtpClient())
        {
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            smtp.Port = 587;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential("mymailaddress@gmail.com", "password");
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            using (MailMessage message = new MailMessage("mymailaddress@gmail.com", "recipient@mail.com", "subject", "content"))
            {
                message.IsBodyHtml = false;
                message.Priority = MailPriority.High;
                using (Attachment data = new Attachment(@"d:\attachedfile.txt"))
                {
                    message.Attachments.Add(data);
                    smtp.Send(message);
                }
            }
        }
    }).ContinueWith(t =>
                    {
                        MessageBox.Show("Delivered...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }, ts);
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.