Exemplo n.º 1
0
        /// <project>Lettera22</project>
        /// <copyright company="Claudio Tortorelli">
        /// Copyright (c) 2018 All Rights Reserved
        /// </copyright>
        /// <author>Claudio Tortorelli</author>
        /// <email>[email protected]</email>
        /// <web>http://www.claudiotortorelli.it</web>
        /// <date>Nov 2018</date>
        /// <summary>
        ///
        /// https://msdn.microsoft.com/it-it/library/system.net.mail.smtpclient(v=vs.110).aspx
        /// </summary>
        /// https://choosealicense.com/licenses/mit/

        public static void Send(string toAddress, string fromAddress, string subject, string bodyText, string attachmentPath = "")
        {
            Globals.m_Logger.Info(toAddress);
            Globals.m_Logger.Info(fromAddress);
            Globals.m_Logger.Info(subject);
            Globals.m_Logger.Info(bodyText);

            //Generate Message
            var mailMessage = new MimeMailMessage();

            mailMessage.From = new MimeMailAddress(fromAddress);
            mailMessage.To.Add(toAddress);
            mailMessage.Subject = subject;
            mailMessage.Body    = bodyText;
            if (attachmentPath.Length > 0 && File.Exists(attachmentPath))
            {
                MimeAttachment attachMessage = new MimeAttachment(attachmentPath);
                mailMessage.Attachments.Add(attachMessage);
            }

            //Create Smtp Client
            var mailer = new MimeMailer(Globals.SMTPHost(), Globals.SMTPPort());

            mailer.User               = Globals.SMTPUsername();
            mailer.Password           = Globals.SMTPPassword();
            mailer.SslType            = SslMode.Ssl;
            mailer.AuthenticationMode = AuthenticationType.Base64;

            //Set a delegate function for call back
            mailer.SendCompleted += compEvent;
            mailer.SendMail(mailMessage);
        }
Exemplo n.º 2
0
        public void EnviarEmailSSLImplicito(string email, string body, string sub, string rutaAdjunto)
        {
            var from = "*****@*****.**";
            var host = "mail.tagor.cl";
            var user = "******";
            var pass = "******";

            //Generate Message
            var mymessage = new MimeMailMessage();

            mymessage.From = new MimeMailAddress(from);

            String[] AMailto = email.Split(';');
            foreach (String mail in AMailto)
            {
                mymessage.To.Add(new MailAddress(mail));
            }

            mymessage.Subject         = sub;
            mymessage.Body            = body;
            mymessage.SubjectEncoding = System.Text.Encoding.UTF8;
            mymessage.HeadersEncoding = System.Text.Encoding.UTF8;
            mymessage.IsBodyHtml      = true;
            mymessage.Priority        = MailPriority.High;



            if (rutaAdjunto != string.Empty)
            {
                MimeAttachment adj = new MimeAttachment(System.Web.HttpContext.Current.Server.MapPath(rutaAdjunto));
                mymessage.Attachments.Add(adj);
            }

            //Create Smtp Client
            var mailer = new MimeMailer(host, 465);

            mailer.User               = user;
            mailer.Password           = pass;
            mailer.SslType            = SslMode.Ssl;
            mailer.AuthenticationMode = AuthenticationType.Base64;

            //Set a delegate function for call back
            mailer.SendCompleted += compEvent;
            mailer.SendMailAsync(mymessage);
        }