Exemplo n.º 1
0
        public override Server creack(String ip, int port, String username, String password, int timeOut)
        {
            SMTP_Client conn   = null;
            Server      server = new Server();

            try
            {
                conn         = new SMTP_Client();
                conn.Timeout = timeOut;
                conn.Connect(ip, port, false);
                if (conn.IsConnected)
                {
                    conn.EhloHelo(ip);
                    AUTH_SASL_Client_Plain authInfo = new AUTH_SASL_Client_Plain(username, password);
                    conn.Auth(authInfo);
                    if (conn.IsAuthenticated)
                    {
                        server.isSuccess = conn.IsAuthenticated;
                        server.banner    = conn.GreetingText;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Disconnect();
                }
            }
            return(server);
        }
Exemplo n.º 2
0
        public bool Authenticate()
        {
            var musername = mSMTPUsername;

            if (mSMTPUsername != null && mSMTPUsername.IndexOf("@") >= 0)
            {
                musername = mSMTPUsername.Substring(0, mSMTPUsername.IndexOf("@"));
            }

            using (SMTP_Client client = new SMTP_Client())
            {
                try
                {
                    client.Connect(mSMTPServer, mSMTPPort);
                    client.EhloHelo(mSMTPServer);

                    client.Authenticate(musername, mSMTPPassword);

                    return(client.IsAuthenticated);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    client.Disconnect();
                }
            }
        }
Exemplo n.º 3
0
 public void CreateHost(ConfigHost host)
 {
     Host = new SMTP_Client();
     Host.Connect(host.Server, host.Port, host.EnableSsl);
     Host.EhloHelo(host.Server);
     Host.Auth(Host.AuthGetStrongestMethod(host.Username, host.Password));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 发送邮件
 /// </summary>
 /// <param name="smtp">Smtp对象</param>
 /// <param name="_strRcpTo">收件地址</param>
 /// <param name="mimeStreams">内存流</param>
 private void SendMail(SMTP_Client smtp, string _strRcpTo, MemoryStream mimeStreams)
 {
     smtp.Connect(this.Smtp, WellKnownPorts.SMTP);
     smtp.EhloHelo(this.Smtp);
     smtp.Authenticate(this.Account, this.CurrentUserMailPassWord);
     smtp.MailFrom(this.CurrentUserMail, -1);
     smtp.RcptTo(_strRcpTo);
     mimeStreams.Position = 0;
     smtp.SendMessage(mimeStreams);
     smtp.Disconnect();
 }
Exemplo n.º 5
0
        public static bool SendMail(string Body, string Title, string reciveEmail)
        {
            bool sended = false;

            using (SMTP_Client client = new SMTP_Client())
            {
                try
                {
                    //与Pop3服务器建立连接
                    client.Connect(smtp, port, false);
                    client.EhloHelo(smtp);
                    //验证身份
                    var authhh = new AUTH_SASL_Client_Plain(sendEmail, sendPassword);
                    client.Auth(authhh);
                    client.MailFrom(sendEmail, -1);
                    //收件人列表
                    client.RcptTo(reciveEmail);
                    //采用Mail_Message类型的Stream
                    Mail_Message m = Create_PlainText_Html_Attachment_Image(reciveEmail, sendEmail, sendEmail, Title, Body);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        m.ToStream(stream, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);
                        stream.Position = 0;
                        client.SendMessage(stream);
                        sended = true;
                    }
                    if (m != null)
                    {
                        m.Dispose();
                    }
                    client.Disconnect();
                    client.Dispose();
                }
                catch {
                    return(false);
                }
            }
            return(sended);
        }
Exemplo n.º 6
0
        private Boolean SendMailNew(bool isAsync, object userState)
        {
            string[] mailTos  = mMailTo;
            string[] mailCcs  = mMailCc;
            string[] mailBccs = mMailBcc;
            Dictionary <string, string> attachments = mMailAttachments;

            var toList = new Dictionary <string, string>();

            foreach (var to in MailTo)
            {
                toList.Add(to, to);
            }

            var musername = mSMTPUsername;

            if (mSMTPUsername != null && mSMTPUsername.IndexOf("@") >= 0)
            {
                musername = mSMTPUsername.Substring(0, mSMTPUsername.IndexOf("@"));
            }

            bool checkspmail = CheckSpecialMail(toList);

            if (!checkspmail && MailCc != null)
            {
                checkspmail = CheckSpecialMail(MailCc);
            }
            if (checkspmail)
            {
                foreach (string address in toList.Keys)
                {
                    using (SMTP_Client client = new SMTP_Client())
                    {
                        client.Timeout = this.Timeout;
                        client.Connect(mSMTPServer, mSMTPPort);
                        client.EhloHelo(mSMTPServer);


                        client.Authenticate(musername, mSMTPPassword);
                        client.MailFrom(mMailFrom, -1);
                        client.RcptTo(address);


                        Mail_Message m = Create_PlainText_Html_Attachment_Image(toList, new Dictionary <string, string>()
                                                                                , mMailFrom,
                                                                                mMailFrom, MailSubject, mMailBody, attachments, "", "", CheckSpecialMail(new string[] { address }));

                        try
                        {
                            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                            {
                                m.ToStream(stream, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);
                                stream.Position = 0;
                                client.SendMessage(stream);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }

                        if (m != null)
                        {
                            m.Dispose();
                        }

                        client.Disconnect();
                    }
                }
                return(true);
            }
            else
            {
                using (SMTP_Client client = new SMTP_Client())
                {
                    client.Timeout = this.Timeout;
                    client.Connect(mSMTPServer, mSMTPPort);
                    client.EhloHelo(mSMTPServer);
                    AUTH_SASL_Client authhh = client.AuthGetStrongestMethod(musername, mSMTPPassword);
                    client.Auth(authhh);
                    client.MailFrom(mMailFrom, -1);
                    foreach (string address in toList.Keys)
                    {
                        client.RcptTo(address);
                    }



                    Mail_Message m = Create_PlainText_Html_Attachment_Image(toList, new Dictionary <string, string>()
                                                                            , mMailFrom,
                                                                            mMailFrom, MailSubject, mMailBody, attachments, "", "", false);

                    try
                    {
                        using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                        {
                            m.ToStream(stream, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);
                            stream.Position = 0;
                            client.SendMessage(stream);
                        }


                        return(true);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (m != null)
                        {
                            m.Dispose();
                        }
                        client.Disconnect();
                    }
                }
            }
        }