private void buttonSend_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSubject.Text)) { MessageBox.Show("Please Enter Subject", "Validation", MessageBoxButtons.OK); txtSubject.Focus(); return; } if (string.IsNullOrEmpty(richtxtMessage.Text)) { MessageBox.Show("Please Enter Message", "Validation", MessageBoxButtons.OK); richtxtMessage.Focus(); return; } var message = richtxtMessage.Text; var emailIds = string.Join(",", _emailIds.Select(x => x.Email).ToArray()); try { var fromEmailId = ConfigurationSettings.AppSettings["FromEmailId"]; var fromEmailPassword = ConfigurationSettings.AppSettings["FromEmailPassword"]; var client = new SmtpClient("smtp.gmail.com") { Port = 587, EnableSsl = true, Timeout = 100000, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential( fromEmailId, fromEmailPassword) }; var msg = new MailMessage(); //msg.To.Add(emailIds); _emailIds.Where(x => !string.IsNullOrEmpty(x.Email)).ToList().ForEach(x => msg.To.Add(x.Email)); msg.From = new MailAddress(fromEmailId); msg.Subject = txtSubject.Text; msg.Body = message; //Attachment data = new Attachment(textBox_Attachment.Text); //msg.Attachments.Add(data); client.Send(msg); var emailHistory = new EmailHistory() { Date = DateTime.Now, EmailIds = emailIds, Subject = txtSubject.Text, Message = message, ExecutiveName = HomePage.UserDetail.UserId }; _uniDb.EmailHistories.InsertOnSubmit(emailHistory); _uniDb.SubmitChanges(); MessageBox.Show(@"Successfully Sent Message."); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
partial void UpdateEmailHistory(EmailHistory instance);
partial void DeleteEmailHistory(EmailHistory instance);
partial void InsertEmailHistory(EmailHistory instance);