/// <summary> /// Send report as an attachment /// </summary> /// <param name="path">file to attach to email</param> /// <param name="verbose">true for verbose positive response</param> public void SendAsAttachment(string path, bool verbose = true) { Cursor.Current = Cursors.WaitCursor; try { var email = new Email(); email.AddTo("Damage Report", @"*****@*****.**"); email.From = @"*****@*****.**"; email.Subject = Subject; if (!string.IsNullOrEmpty(CC)) { email.AddCC(CC, CC); } email.AddFileAttachment(path); SendMail(email); Cursor.Current = Cursors.Default; if (verbose) { MessageBox.Show("Email Send Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception e) { Cursor.Current = Cursors.Default; var reason = string.Format(@"Failed to send email : {0}", e.Message); MessageBox.Show(reason, @"Error", MessageBoxButtons.OK); } }
private static bool FillMail(List<string> EmailReceive, string SubjectEmail, List<string> PathAttachment, ref Email Mail) { if (EmailReceive == null) return false; for (int i = 0; i < EmailReceive.Count; i++) if (!Mail.AddTo("", EmailReceive[i])) return false; Mail.Subject = SubjectEmail; if (PathAttachment != null) for (int i = 0; i < PathAttachment.Count; i++) Mail.AddFileAttachment(PathAttachment[i]); return true; }