コード例 #1
0
ファイル: Email.cs プロジェクト: PhoenixRFA/AS_Emails
        //Grek
        //public static void SendMail2(string from, string displayName, string to, List<MailAddress> bcc, List<MailAddress> cc, string subject, string body,
        //   string mailServer, string mailUsername, string mailPassword, int port, bool ssl = true, string attach = "")
        //{

        //    var builder = new BodyBuilder();
        //    MimeMessage mail = new MimeMessage();

        //    mail.From.Add(new MailboxAddress("", from));
        //    mail.To.Add(new MailboxAddress("", to.FirstOrDefault().Address));
        //    mail.Subject = "Mail Subject";
        //    builder.HtmlBody = "<html><body>Body Text";
        //    builder.HtmlBody += "</body></html>";
        //    mail.Body = builder.ToMessageBody();

        //    using (var client = new MailKit.Net.Smtp.SmtpClient())
        //    {
        //        client.Connect(mailServer, 465, true);
        //        client.AuthenticationMechanisms.Remove("XOAUTH2"); //' Do not use OAUTH2
        //        client.Authenticate(mailUsername, mailPassword); //' Use a username / password to authenticate.
        //        client.Send(mail);
        //        client.Disconnect(true);
        //    }
        //}
        //Grek


        // ненадежно
        public static void DirectMail()
        {
            EASendMail.SmtpMail   oMail = new EASendMail.SmtpMail("TryIt");
            EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();

            // Set sender email address, please change it to yours
            oMail.From = "*****@*****.**"; //[email protected]

            // Set recipient email address, please change it to yours
            oMail.To = "*****@*****.**";

            // Set email subject
            oMail.Subject = "direct email sent from c# project";

            // Set email body
            oMail.TextBody = "this is a test email sent from c# project directly";

            // Set SMTP server address to "".
            EASendMail.SmtpServer oServer = new EASendMail.SmtpServer("");

            // Do not set user authentication
            // Do not set SSL connection

            try
            {
                Console.WriteLine("start to send email directly ...");
                oSmtp.SendMail(oServer, oMail);
                Console.WriteLine("email was sent successfully!");
            }
            catch (Exception ep)
            {
                Console.WriteLine("failed to send email with the following error:");
                Console.WriteLine(ep.Message);
            }
        }
コード例 #2
0
 /// <summary>
 /// this function will check weather a mail adress is valid or not
 /// </summary>
 /// <param name="email">the email to be checked</param>
 /// <returns>wether the email is a match or not</returns>
 public static Boolean TestMail(String email)
 {
     if (!CheckMailStructure(email))
     {
         return(false);
     }
     //first we set the mail smtp client
     EASendMail.SmtpMail   oMail   = new EASendMail.SmtpMail("TryIt");
     EASendMail.SmtpClient oSmtp   = new EASendMail.SmtpClient();
     EASendMail.SmtpServer oServer = new EASendMail.SmtpServer("");
     //then we set a generic sender
     oMail.From = "*****@*****.**";
     //and the mail we want to check vor validity
     oMail.To = email;
     try
     {
         oSmtp.TestRecipients(oServer, oMail);
         return(true);
     }
     catch
     {
         return(false);
     }
 }