コード例 #1
0
        private void butnSendMail_Click(object sender, System.EventArgs e)
        {
            butnSendMail.Enabled = false;
            try {
                Indy.Sockets.Message LMsg = new Indy.Sockets.Message();
                LMsg.From.Text = textFrom.Text.Trim();
                LMsg.Recipients.Add().Text = textTo.Text.Trim();
                LMsg.Subject   = textSubject.Text.Trim();
                LMsg.Body.Text = textMsg.Text;

                // Attachment example
                // new AttachmentFile(LMsg.MessageParts, @"c:\temp\Hydroponics.txt");

                SMTP LSMTP = new SMTP();
                LSMTP.OnStatus += new Indy.Sockets.TIdStatusEvent(SMTPStatus);
                LSMTP.Host      = textSMTPServer.Text.Trim();
                LSMTP.Connect();
                try {
                    LSMTP.Send(LMsg);
                    Status("Completed");
                }
                finally {
                    LSMTP.Disconnect();
                }
            }
            finally {
                butnSendMail.Enabled = true;
            }
        }
コード例 #2
0
        public static void SendThread()
        {
            //create SMTP object
            SMTP objSMTP = new SMTP();
            objSMTP.SMTPServers.Add("smtp.socketlabs.com", 25, 60, SMTPAuthMode.AuthLogin, "your_smtp_user", "your_smtp_password");

            /*
             * this sample just sends one message per thread/connection but in the real world you should send about
             * 50-100 messages per connection. You will have to add your database retrieval and loop management here
             *
             * i.e. grab 50 records from db, connect, loop through and send all 50 and then disconnect
             * repeat as long as there are more records to process in database
            */

            //establish connection and keep it open for all messages we send
            objSMTP.Connect();

            EmailMessage objMessage = new EmailMessage();
            objMessage.From = new Address("*****@*****.**", "Sender Name");
            objMessage.Recipients.Add("*****@*****.**", "Recipient Name", RecipientType.To);
            objMessage.Subject = "Subject...";
            objMessage.BodyParts.Add("Hi ##FIRSTNAME##, Thank you for your interest in ##PRODUCT##.", BodyPartFormat.Plain, BodyPartEncoding.QuotedPrintable);
            Dictionary<string, string> tokens = new Dictionary<string, string>();
            tokens["##FIRSTNAME##"] = "John";
            tokens["##PRODUCT##"] = "SocketLabs Email On-Demand";
            objMessage.BodyParts[0].Body = BulkReplace(objMessage.BodyParts[0].Body, tokens);

            objSMTP.Send(objMessage);

            //close connection after all messages have been sent
            objSMTP.Disconnect();

            Interlocked.Decrement(ref threadsOpen);
        }
コード例 #3
0
        public static void SendThread()
        {
            //create SMTP object
            SMTP objSMTP = new SMTP();

            objSMTP.SMTPServers.Add("smtp.socketlabs.com", 25, 60, SMTPAuthMode.AuthLogin, "your_smtp_user", "your_smtp_password");

            /*
             * this sample just sends one message per thread/connection but in the real world you should send about
             * 50-100 messages per connection. You will have to add your database retrieval and loop management here
             *
             * i.e. grab 50 records from db, connect, loop through and send all 50 and then disconnect
             * repeat as long as there are more records to process in database
             */


            //establish connection and keep it open for all messages we send
            objSMTP.Connect();


            EmailMessage objMessage = new EmailMessage();

            objMessage.From = new Address("*****@*****.**", "Sender Name");
            objMessage.Recipients.Add("*****@*****.**", "Recipient Name", RecipientType.To);
            objMessage.Subject = "Subject...";
            objMessage.BodyParts.Add("Hi ##FIRSTNAME##, Thank you for your interest in ##PRODUCT##.", BodyPartFormat.Plain, BodyPartEncoding.QuotedPrintable);
            Dictionary <string, string> tokens = new Dictionary <string, string>();

            tokens["##FIRSTNAME##"]      = "John";
            tokens["##PRODUCT##"]        = "SocketLabs Email On-Demand";
            objMessage.BodyParts[0].Body = BulkReplace(objMessage.BodyParts[0].Body, tokens);

            objSMTP.Send(objMessage);

            //close connection after all messages have been sent
            objSMTP.Disconnect();



            Interlocked.Decrement(ref threadsOpen);
        }