private void buttonSend_Click(object sender, EventArgs e) { SmtpOptions __Smtp_options = new SmtpOptions(); try { __Smtp_options.Email = txbx_email.Text; __Smtp_options.Password = txbx_pass.Text; __Smtp_options.DetectServer(); __Smtp_options.ServerLize(txbxServer.Text); // set server and port SmtpClient cli = new SmtpClient(__Smtp_options.Server,__Smtp_options.Port); MailMessage msg = new MailMessage(); msg.From = new MailAddress(txbx_from.Text ); msg.To.Add(txbx_To.Text); msg.Body = txbx_Body.Text; msg.Subject = txbx_Sub.Text; cli.UseDefaultCredentials = false; cli.EnableSsl = true; if (txbx_Att.Text != "") { if (!txbx_Att.Text.Contains(",")) { if (System.IO.File.Exists(txbx_Att.Text)) msg.Attachments.Add(new Attachment(txbx_Att.Text)); } else { string[] fpaths = txbx_Att.Text.Split(new char[] { ',' }); foreach(string fp in fpaths) { if(System.IO.File.Exists(fp)) msg.Attachments.Add(new Attachment(fp)); } } } cli.Credentials = __Smtp_options.Credentials(); cli.Send(msg); msg = null; MessageBox.Show("sent"); } catch(Exception ex) { string msg = ex.Message + Environment.NewLine + "Check ur crediential" + Environment.NewLine ; msg += (Environment.NewLine+ Environment.NewLine+"Check SMTP security settings"); if (__Smtp_options.Email.Contains("@gmail")) msg += ("Check google security at https://www.google.com/settings/security/lesssecureapps"); MessageBox.Show(msg, "Server Error"); } }
private void buttonSend_Click(object sender, EventArgs e) { SmtpOptions __Smtp_options = new SmtpOptions(); try { __Smtp_options.Email = txbx_email.Text; __Smtp_options.Password = txbx_pass.Text; __Smtp_options.DetectServer(); __Smtp_options.ServerLize(txbxServer.Text); // set server and port SmtpClient cli = new SmtpClient(__Smtp_options.Server, __Smtp_options.Port); MailMessage msg = new MailMessage(); msg.From = new MailAddress(txbx_from.Text); msg.To.Add(txbx_To.Text); msg.Body = txbx_Body.Text; msg.Subject = txbx_Sub.Text; cli.UseDefaultCredentials = false; cli.EnableSsl = true; if (txbx_Att.Text != "") { if (!txbx_Att.Text.Contains(",")) { if (System.IO.File.Exists(txbx_Att.Text)) { msg.Attachments.Add(new Attachment(txbx_Att.Text)); } } else { string[] fpaths = txbx_Att.Text.Split(new char[] { ',' }); foreach (string fp in fpaths) { if (System.IO.File.Exists(fp)) { msg.Attachments.Add(new Attachment(fp)); } } } } cli.Credentials = __Smtp_options.Credentials(); cli.Send(msg); msg = null; MessageBox.Show("sent"); } catch (Exception ex) { string msg = ex.Message + Environment.NewLine + "Check ur crediential" + Environment.NewLine; msg += (Environment.NewLine + Environment.NewLine + "Check SMTP security settings"); if (__Smtp_options.Email.Contains("@gmail")) { msg += ("Check google security at https://www.google.com/settings/security/lesssecureapps"); } MessageBox.Show(msg, "Server Error"); } }