Ejemplo n.º 1
0
        /// <summary>
        /// 同步发送
        /// </summary>
        /// <param name="subject">主题</param>
        /// <param name="body">邮件内容</param>
        /// <param name="attachment">附件</param>
        /// <param name="receptMail">接收地址[email protected]</param>
        /// <param name="sendMail">发送邮件地址</param>
        /// <param name="sendName">发送名称</param>
        /// <param name="userName">服务器账号</param>
        /// <param name="password">服务器账户密码</param>
        /// <param name="smtpHost">SMTP服务器</param>
        /// <param name="smtpPort">SMTP服务器端口</param>
        private void SendEmailSync(string subject, string body, string attachment, string receptMail, string sendMail, string sendName, string userName, string password, string smtpHost, int smtpPort)
        {
            try
            {
                SmtpConfig.VerifyAddresses = false;
                EmailAddress from = new EmailAddress(sendMail, sendName);
                EmailAddress to = new EmailAddress(receptMail);
                MailMessage msg = new MailMessage(from, to);
                msg.Charset = "gb2312";
                msg.Subject = subject;
                msg.HtmlBody = HttpUtility.HtmlDecode(body);
                Smtp smtp = new Smtp(smtpHost, smtpPort);

                // 在SMTP服务器上的用户名和密码
                smtp.Username = userName;
                smtp.Password = password;
                smtp.SendMail(msg);
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        public static string SendPassword(string strEmail)
        {

            try
            {
                string smtpHost = "smtp.163.com";
                int smtpPort = 25;
                string senderEmail = "*****@*****.**";
                string senderName = "zhuangrong";
                string recipientEmail = strEmail;
                string subject = "您在PowerSite的密码";
                string body = "这是来自PowerSite的密码回复邮件。";

                SmtpConfig.VerifyAddresses = false;
                EmailAddress from = new EmailAddress(senderEmail, senderName);
                EmailAddress to = new EmailAddress(recipientEmail);
                MailMessage msg = new MailMessage(from, to);
                msg.Charset = "gb2312";
                msg.Subject = subject;
                msg.Body = body;

                Smtp smtp = new Smtp(smtpHost, smtpPort);
                smtp.Username = "******";
                smtp.Password = "******";
                smtp.SendMail(msg);
                return "OK";

            }
            catch (MalformedAddressException mfa)
            {
                return mfa.Message.Substring(0, mfa.Message.Length - 4);
            }
            catch (SmtpException se)
            {
                return se.Message.Substring(0, se.Message.Length - 4);
            }
            catch (Exception ex)
            {
                return ex.Message.Substring(0, ex.Message.Length - 4);
            }
        }       
Ejemplo n.º 3
0
 public void Detach()
 {
     // Detach the event and delete the list
     this.smtp.Connected 				-= new EventHandler(SmtpConnected);
     this.smtp.Authenticated 			-= new EventHandler(SmtpAuthenticated);
     this.smtp.StartedMessageTransfer	-= new EventHandler(SmtpStartedTransfer);
     this.smtp.EndedMessageTransfer		-= new EventHandler(SmtpEndedTransfer);
     this.smtp.Disconnected 				-= new EventHandler(SmtpDisconnected);
     this.smtp = null;
 }
Ejemplo n.º 4
0
 public SmtpEventListener(Smtp smtp)
 {
     this.smtp = smtp;
     // Add "ListChanged" to the Changed event on "List".
     this.smtp.Connected 				+=	new EventHandler(SmtpConnected);
     this.smtp.Authenticated				+=	new EventHandler(SmtpAuthenticated);
     this.smtp.StartedMessageTransfer	+= 	new EventHandler(SmtpStartedTransfer);
     this.smtp.EndedMessageTransfer		+=	new EventHandler(SmtpEndedTransfer);
     this.smtp.Disconnected 				+= 	new EventHandler(SmtpDisconnected);
 }
Ejemplo n.º 5
0
        protected void Init()
        {
            subject 		= "Test Subject. International chars: ËÇÅÃÄÄÅÂÀèéêëìíîïñaÿc + 功能超强得不得了";
                body 			= "Hello Jane.\r\n This is the body of the mail message. \r\nInternational chars: ËÇÅÃÄÄÅÂÀèéêë\r\nìíîïñaÿc";

                htmlBody = new StringBuilder();
                htmlBody.Append("<HTML><HEAD></HEAD><BODY bgColor=\"#00ffff\"><b>Hello Jane. This is the body of the HTML mail message. International chars: ËÇÅÃÄÄÅÂÀèéêëìíîïñaÿc</b></BODY></HTML>");

                senderAddress 		= new EmailAddress("sender@localhost", "John Sender");
                recipientAddress 	= new EmailAddress("administrator@localhost", "Jane Doe");

                replyToAddress 		= new EmailAddress("replyTo@localhost", "ReplyTo Name");
                ccAddress 		= new EmailAddress("ccAddress@localhost", "CC Name");
                bccAddress		= new EmailAddress("bccAddress@localhost", "BCC Name");

                msg 			= new MailMessage("*****@*****.**", "*****@*****.**");

                smtpHost 		= "localhost";
                smtpPort 		= 25;

                smtp			= new Smtp();
                smtp.Host 		= smtpHost;
                smtp.Port 		= smtpPort;

                // Add Smtp event listener
                SmtpEventListener listener = new SmtpEventListener(smtp);
        }
Ejemplo n.º 6
0
 protected void Destroy()
 {
     smtp = null;
 }