Example #1
0
        static UMail()
        {
            ItemAttributes ia = Config.DefaultService.ConfigAttributes;

            Mailer = new Mailer();

            Mailer.Templates.Add(MailTemplateE.ActivateAccount.ToString(), ia.ToString(AttributeE.ServiceTemplateEmailSubjectActivateAccount), ia.ToString(AttributeE.ServiceTemplateEmailBodyActivateAccount));
            Mailer.Templates.Add(MailTemplateE.ForgotPassword.ToString(), ia.ToString(AttributeE.ServiceTemplateEmailSubjectForgotPassword), ia.ToString(AttributeE.ServiceTemplateEmailBodyForgotPassword));

            Mailer.SmtpServer = ia.ToString(AttributeE.ServiceSmtpServer);
            Mailer.SmtpPort = ia.ToInt32(AttributeE.ServiceSmtpPort);
            Mailer.SmtpAuthenticate = ia.ToBool(AttributeE.ServiceSmtpAuthenticate);
            Mailer.SmtpUseSsl = ia.ToBool(AttributeE.ServiceSmtpUseSsl);
            Mailer.SmtpUserId = ia.ToString(AttributeE.ServiceSmtpUserId);
            Mailer.SmtpPassword = ia.ToString(AttributeE.ServiceSmtpPassword);
            Mailer.From = ia.ToString(AttributeE.ServiceSmtpFrom);
        }
Example #2
0
        public MailVerifyResult DoVerify(Mailer mail)
        {
            this.mail = mail;
            host = Dns.Resolve(mail.SmtpServer);
            ourSmtp = new IPEndPoint(host.AddressList[0], mail.SmtpPort);
            socket = new Socket(ourSmtp.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(ourSmtp);
            if (!CheckResponse(SmtpResponse.ConnectSuccess))
            {
                socket.Close();
                return MailVerifyResult.ConnectFailed;
            }

            // The SMTP HELO clause is the stage of the SMTP protocol 
            // where a SMTP server introduce them selves to each other. 
            // The sending server will identify who it is and the receiving 
            // server will (as per RFC) accept any given name. There is no 
            // requirement to give the correct information at this stage. 
            SendData(string.Format("HELO {0}" + Environment.NewLine, Dns.GetHostName()));
            if (!CheckResponse(SmtpResponse.GenericSuccess))
            {
                socket.Close();
                return MailVerifyResult.HeloFailed;
            }

            // The SMTP MAIL clause defines the sender of the mail message. 
            // There is no requirement for this address to be the same as 
            // the address given in the From clause of the message itself.
            SendData(string.Format("MAIL From: {0}" + Environment.NewLine, mail.From));
            if (!CheckResponse(SmtpResponse.GenericSuccess))
            {
                socket.Close();
                return MailVerifyResult.MailFailed;
            }

            if (!VerifyAddress(mail.To))
            {
                socket.Close();
                return MailVerifyResult.ToFailed;
            }

            if (!VerifyAddress(mail.Cc))
            {
                socket.Close();
                return MailVerifyResult.CcFailed;
            }

            if (!VerifyAddress(mail.Bcc))
            {
                socket.Close();
                return MailVerifyResult.BccFailed;
            }

            if (MailVerifyLevel == MailVerifyLevel.Address)
            {
                return MailVerifyResult.Ok;
            }

            #region Create Message
            StringBuilder msg = new StringBuilder();

            msg.Append("From: " + mail.From + Environment.NewLine);
            AddRecipent(msg, mail.To, RecipentType.To);
            AddRecipent(msg, mail.Cc, RecipentType.Cc);
            AddRecipent(msg, mail.Bcc, RecipentType.Bcc);
            msg.Append("Date: ");
            msg.Append(DateTime.Now.ToString("ddd, d M y H:m:s z"));
            msg.Append(Environment.NewLine);
            msg.Append("Subject: " + mail.Subject + Environment.NewLine);
            msg.Append("X-Mailer: SMTPDirect v1" + Environment.NewLine);
            AppendBody(msg);
            #endregion

            SendData(("DATA" + Environment.NewLine));
            if (!CheckResponse(SmtpResponse.DataSuccess))
            {
                socket.Close();
                return MailVerifyResult.DataFailed;
            }

            SendData(msg.ToString());
            if (!CheckResponse(SmtpResponse.GenericSuccess))
            {
                socket.Close();
                return MailVerifyResult.SendFailed;
            }

            SendData("QUIT" + Environment.NewLine);
            if (!CheckResponse(SmtpResponse.QuitSuccess))
            {
                socket.Close();
                return MailVerifyResult.QuitFailed;
            }
            else
            {
                socket.Close();
                return MailVerifyResult.Ok;
            }
        }
Example #3
0
        public MailVerifyResult Verify(Mailer mail)
        {
            if (level == MailVerifyLevel.None)
            {
                return MailVerifyResult.Ok;
            }

            MailVerifyResult result = MailVerifyResult.Failed;

            MailVerifier v = new MailVerifier();

            try
            {
                result = v.DoVerify(mail);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return result;
        }