private void sendMessageButton_Click(object sender, EventArgs e) { this.AddLogEntry("Creating message."); // We create the message object ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message(); // We assign the sender email message.From.Email = this.fromEmailTextbox.Text; // We assign the recipient email message.To.Add(this.toEmailTextbox.Text); // We assign the subject message.Subject = this.subjectTextbox.Text; // We assign the body text message.BodyText.Text = this.bodyTextTextbox.Text; // We send the email using the specified SMTP server this.AddLogEntry("Sending message."); try { SmtpClient smtpClient = new SmtpClient(); SslHandShake handShake = new SslHandShake("mail.activeup.com", System.Security.Authentication.SslProtocols.Ssl3); handShake.ServerCertificateValidationCallback = MyServerCertificateValidationCallback; this.AddLogEntry("Message sent successfully."); } catch (SmtpException ex) { this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } }
public string ConnectSsl(string host, int port, string user, string pass, SslHandShake sslHandShake) { this.OnConnecting(); base.Connect(host, port); this.DoSslHandShake(sslHandShake); string response = this.ReadLine(); this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response)); this.OnAuthenticating(new ActiveUp.Net.Mail.AuthenticatingEventArgs(user, pass, host)); response = this.Command("USER " + user); string presponse = this.Command("PASS " + pass); this.OnAuthenticated(new ActiveUp.Net.Mail.AuthenticatedEventArgs(user, pass, host, response)); /*response = this.Command("STAT"); var splited = response.Split(' '); this._messageCount = System.Convert.ToInt32(splited[1]); this._totalSize = System.Convert.ToInt32(splited[2]);*/ return presponse; }
public IAsyncResult BeginConnectSsl(string host, string user, string pass, SslHandShake sslHandShake, AsyncCallback callback) { return this.BeginConnectSsl(host, 995, user, pass, sslHandShake, callback); }
public string ConnectSsl(string host, string user, string pass, SslHandShake sslHandShake) { return this.ConnectSsl(host, 995, user, pass, sslHandShake); }
public IAsyncResult BeginConnectSsl(string host, int port, string user, string pass, SslHandShake sslHandShake, AsyncCallback callback) { this._delegateConnectSslAuth = this.ConnectSsl; return this._delegateConnectSslAuth.BeginInvoke(host, port, user, pass, sslHandShake, callback, this._delegateConnectSslAuth); }
public Boolean SendSessionedMail(Boolean UseSSL, Boolean UseMD5, System.Security.Authentication.SslProtocols protocol) { Message message = new Message(); ServerCollection Hosts = null; int Port=0; string UserName=string.Empty; string Password=string.Empty; bool PORTExist = false; try { if (Session["From"] != null) { message.From.Email = Session["From"].ToString(); } else { return false; //throw new Exception("From Email is a mandatory information"); } if (Session["FromName"] != null) { message.From.Name = Session["FromName"].ToString(); } else { return false; //throw new Exception("From Name is a mandatory information"); } if (Session["To"] != null) { message.To.AddRange((AddressCollection)Session["To"]); } else { return false; //throw new Exception("Email to is a mandatory information"); } if (Session["CC"] != null) { message.Cc.AddRange((AddressCollection)Session["CC"]); } if (Session["BCC"] != null) { message.Bcc.AddRange((AddressCollection)Session["BCC"]); } if (Session["Subject"] != null) { message.Subject = Session["Subject"].ToString(); } else { //May not be needed //throw new Exception("Subject to is a mandatory information"); } if (Session["BodyText"] != null) { message.BodyText.Text = Session["BodyText"].ToString(); } if (Session["BodyHTML"] != null) { message.BodyHtml.Text = Session["BodyHTML"].ToString(); } if (Session["Hosts"] != null) { Hosts = (ServerCollection)Session["Hosts"]; } if (Session["Port"] != null) { Port = (int)Session["Port"]; PORTExist = true; } if (Session["User"] != null) { UserName = (string)Session["User"]; } if (Session["Password"] != null) { Password = (string)Session["Password"]; } //TODO - Need to find a way to manage multiple attachemnts // Session is not a solution as it will generate too much network traffic // Probably need to store it locally and associate with Session ID if (UserName.Length > 0 && Password.Length > 0 && Hosts.Count > 0 && UseSSL) { //Use SSL to send mail SmtpClient smtpClient = new SmtpClient(); SslHandShake handShake = new SslHandShake(Hosts[0].Host, protocol); handShake.ServerCertificateValidationCallback = MyServerCertificateValidationCallback; message.Send(Hosts[0].Host, UserName, Password, UseMD5 ? SaslMechanism.CramMd5 : SaslMechanism.Login); return true; } else if (UserName.Length > 0 && Password.Length > 0 && Hosts.Count > 0 && PORTExist) { //Use Authentication for sending mail message.Send(Hosts[0].Host, Port, UserName, Password, UseMD5 ? SaslMechanism.CramMd5 : SaslMechanism.Login); return true; } else if ((UserName.Trim().Length == 0 || Password.Length == 0) && Hosts.Count > 0 && PORTExist) { //Use specified port for sending mail message.Send(Hosts[0].Host, Port); return true; } else if ((UserName.Trim().Length == 0 || Password.Length == 0) && Hosts.Count > 0 && !PORTExist) { //Send without authentication message.Send(Hosts); return true; } else { //Send directly without specifying a server message.DirectSend(); return true; } return false; } catch (Exception ex) { return false; } finally { message = null; } }