private void btnComposeMail_Click(object sender, System.EventArgs e) { if (smtp1.Active || pop31.Active) { return; } MessageFrm dlg = new MessageFrm(); if (dlg.ShowDialog() == DialogResult.OK) { try { mailMessage1.BuildMessage(dlg.memBody.Text, ""); mailMessage1.From.FullAddress = dlg.edtFrom.Text; mailMessage1.ToList.EmailAddresses = dlg.edtTo.Text; mailMessage1.Subject = dlg.edtSubject.Text; smtp1.Server = edtSmtpServer.Text; smtp1.UserName = edtUser.Text; smtp1.Password = edtPassword.Text; smtp1.Open(); smtp1.Send(mailMessage1); smtp1.Close(); MessageBox.Show("The message was sent successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); smtp1.Close(); } } }
private void btnSend_Click(object sender, System.EventArgs e) { if (smtp1.Active) { return; } smtp1.Server = edtServer.Text; smtp1.Port = Convert.ToInt32(edtPort.Text); smtp1.UserName = edtUser.Text; smtp1.Password = edtPassword.Text; smtp1.UseTls = cbUseTLS.Checked ? ClientTlsMode.Automatic : ClientTlsMode.None; smtp1.Open(); try { mailMessage1.BuildMessage(memBody.Text, ""); mailMessage1.From.FullAddress = edtFrom.Text; mailMessage1.ToList.EmailAddresses = edtTo.Text; mailMessage1.Subject = edtSubject.Text; smtp1.Send(mailMessage1); MessageBox.Show("The message was sent successfully."); } finally { smtp1.Close(); } }
protected void Button1_Click(object sender, System.EventArgs e) { mailMessage1.BuildMessage(edtBody.Text, ""); mailMessage1.From.FullAddress = edtFrom.Text; mailMessage1.ToList.EmailAddresses = edtTo.Text; mailMessage1.Subject = edtSubject.Text; smtp1.Server = edtServer.Text; smtp1.UserName = edtUser.Text; smtp1.Password = edtPassword.Text; try { smtp1.Open(); smtp1.Send(mailMessage1); lblStatus.Visible = true; lblStatus.BackColor = Color.White; lblStatus.ForeColor = Color.Black; lblStatus.Text = "The message was sent successfully"; } catch (Exception ex) { lblStatus.Visible = true; lblStatus.BackColor = Color.Red; lblStatus.ForeColor = Color.White; lblStatus.Text = ex.Message; } smtp1.Close(); }
private void btnSend_Click(object sender, System.EventArgs e) { if (smtp1.Active || pop31.Active) { MessageBox.Show("Message sending / retrieving is in progress"); return; } if (StringUtils.IsEmpty(edtAttachment.Text)) { mailMessage1.BuildMessage(memBody.Text, String.Empty); } else { mailMessage1.BuildMessage(memBody.Text, new string[] { edtAttachment.Text }); } mailMessage1.Subject = "Message Subject"; mailMessage1.From.FullAddress = edtFrom.Text; mailMessage1.ToList.EmailAddresses = edtTo.Text; progressBar1.Value = 0; lblProgress.Text = "%"; smtp1.Server = edtServer.Text; smtp1.UserName = edtUser.Text; smtp1.Password = edtPassword.Text; try { smtp1.Open(); smtp1.Send(mailMessage1); smtp1.Close(); lblProgress.Text = "100 %"; MessageBox.Show("Done"); } catch (Exception ex) { MessageBox.Show(ex.Message); smtp1.Close(); } }
private void btnSend_Click(object sender, System.EventArgs e) { if (smtp1.Active) { return; } oAuth1.AuthUrl = "https://accounts.google.com/o/oauth2/auth"; oAuth1.TokenUrl = "https://accounts.google.com/o/oauth2/token"; oAuth1.RedirectUrl = "http://localhost"; //You need to specify both Client ID and Client Secret of your Google API Project. oAuth1.ClientID = "421475025220-6khpgoldbdsi60fegvjdqk2bk4v19ss2.apps.googleusercontent.com"; oAuth1.ClientSecret = "_4HJyAVUmH_iVrPB8pOJXjR1"; oAuth1.Scope = "https://mail.google.com/"; smtp1.Server = "smtp.gmail.com"; smtp1.Port = 587; smtp1.UseTls = ClientTlsMode.Explicit; smtp1.UserName = edtFrom.Text; smtp1.Authorization = oAuth1.GetAuthorization(); smtp1.Open(); try { mailMessage1.BuildMessage(memBody.Text, ""); mailMessage1.From.FullAddress = edtFrom.Text; mailMessage1.ToList.EmailAddresses = edtTo.Text; mailMessage1.Subject = edtSubject.Text; smtp1.Send(mailMessage1); MessageBox.Show("The message was sent successfully."); } finally { smtp1.Close(); } }