コード例 #1
0
        static void SendMail()
        {
            try
            {
                // Declare msg as MailMessage instance
                MailMessage  msg    = new MailMessage("*****@*****.**", "*****@*****.**", "Test subject", "Test body");
                SmtpClient   client = GetSmtpClient2();
                object       state  = new object();
                IAsyncResult ar     = client.BeginSend(msg, Callback, state);

                Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
                string answer = Console.ReadLine();

                // If the user canceled the send, and mail hasn't been sent yet,
                if (answer != null && answer.StartsWith("c"))
                {
                    client.CancelAsyncOperation(ar);
                }

                msg.Dispose();
                Console.WriteLine("Goodbye.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        public Task SendEmailAsync(string email, string subject, string htmlMessage)
        {
            var fullSubject = $"Data warehouse Access (do not reply) - {subject}";
            var accessToken = GetAccessToken();
            var message     = new MailMessage(_userName, email, fullSubject, htmlMessage)
            {
                IsBodyHtml = true
            };
            var client = new SmtpClient(_host, _port, _userName, accessToken, true)
            {
                SecurityOptions = SecurityOptions.SSLImplicit
            };

            client.Timeout = 400000;
            return(client.BeginSend(message) as Task);
        }
コード例 #3
0
        public void Enviar()
        {
            ServerCollection  servers  = new ServerCollection();
            Server            Nlayer   = new Server();
            Message           message  = new Message();
            MimeBody          mimeBody = new MimeBody(BodyFormat.Html);
            AddressCollection destinos = new AddressCollection();

            Nlayer.Host     = "mail.softwareNlayer.com";
            Nlayer.Password = "******";
            Nlayer.Port     = 25;
            Nlayer.Username = "******";

            servers.Add(Nlayer);

            if (_destinos != null)
            {
                foreach (string destino in _destinos)
                {
                    destinos.Add(new Address(destino));
                }
            }

            if (_adjuntos != null)
            {
                foreach (string adjunto in _adjuntos)
                {
                    message.Attachments.Add(adjunto, false);
                }
            }

            mimeBody.Text = _mensaje;

            message.BodyHtml     = mimeBody;
            message.Date         = DateTime.Now;
            message.From         = new Address("*****@*****.**");
            message.Organization = "Nlayer Software";
            message.Priority     = MessagePriority.Normal;
            message.To           = destinos;
            message.Subject      = _asunto;

            AsyncCallback beginCallback = IniciaEnvio;

            SmtpClient.BeginSend(message, servers, beginCallback);
        }
コード例 #4
0
        private void _bSendMessage_Click(object sender, EventArgs e)
        {
            this.AddLogEntry("Creating message.");

            // We create the message object
            ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();

            // We assign the sender email
            message.From.Email = this._tbFromEmail.Text;

            // We assign the recipient email
            message.To.Add(this._tbToEmail.Text);

            // We assign the subject
            message.Subject = this._tbSubject.Text;

            // We assign the body text
            message.BodyText.Text = this._tbBodyText.Text;

            // We send the email using the specified SMTP server
            this.AddLogEntry("Sending message.");

            try
            {
                //Send the message specifying the address of the smtp server, asynchronously
                //SendingDone method gets the notification once the message sending is done.
                SmtpClient.BeginSend(message, this._tbSmtpServer.Text, new AsyncCallback(this.SendingDone));
            }

            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
コード例 #5
0
ファイル: SmtpMessage.cs プロジェクト: zvit-cc/MailSystem.NET
 public IAsyncResult BeginSend(string host, AsyncCallback callback)
 {
     return(SmtpClient.BeginSend(this, host, callback));
 }
コード例 #6
0
ファイル: SmtpMessage.cs プロジェクト: zvit-cc/MailSystem.NET
 public IAsyncResult BeginSend(string host, int port, string username, string password, SaslMechanism mechanism, AsyncCallback callback)
 {
     return(SmtpClient.BeginSend(this, host, port, username, password, mechanism, callback));
 }
コード例 #7
0
ファイル: SmtpMessage.cs プロジェクト: zvit-cc/MailSystem.NET
 public IAsyncResult BeginSend(string host, int port, AsyncCallback callback)
 {
     //CheckBuiltMimePartTree();
     return(SmtpClient.BeginSend(this, host, port, callback));
 }
コード例 #8
0
ファイル: SmtpMessage.cs プロジェクト: zvit-cc/MailSystem.NET
 public IAsyncResult BeginSend(ServerCollection servers, AsyncCallback callback)
 {
     return(SmtpClient.BeginSend(this, servers, callback));
 }