Example #1
0
        /// <summary>
        /// Create a collection of message based on the merging of the message and a datasource.
        /// </summary>
        /// <param name="message">The message to use as a base for merging.</param>
        /// <param name="dataSource">The datasource to use for merging.</param>
        /// <param name="send">Specify if you want to send the message when merged.</param>
        /// <returns>The merged MessageCollection.</returns>
        public MessageCollection MergeCollection(Message message, object dataSource, bool send)
        {
            MessageCollection messages = new MessageCollection();

            if (dataSource.GetType().ToString() == "System.Data.DataSet")
            {
                dataSource = ((System.Data.DataSet)dataSource).Tables[0];
            }

            IEnumerator items = GetEnumerator(dataSource);

            // Determine max
            int total = 0;            //, messageNumber = 0, messageSent = 0;

            while (items.MoveNext())
            {
                total++;
            }

            items.Reset();

            if (items != null)
            {
                while (items.MoveNext())
                {
                    Message newMessage = message.Clone();
                    this.MergeMessage(newMessage, items.Current);
                    messages.Add(newMessage);

                    /*string file = @"c:\temp\_amail_\test.eml";
                     * if (File.Exists(file))
                     *      File.Delete(file);
                     * newMessage.StoreToFile(file);*/

                    if (send)
                    {
                        if (this.SmtpServers.Count > 0)
                        {
                            //newMessage.Send(this.SmtpServers);
                            SmtpClient.Send(newMessage, this.SmtpServers);
                        }
                        else
                        {
                            //newMessage.DirectSend();
                            SmtpClient.DirectSend(newMessage);
                        }
                    }
                }

                ActiveUp.Net.Mail.Logger.AddEntry("Message created successfully.", 2);
            }

            return(messages);
        }
Example #2
0
        private void sendTestMessageButton_Click(object sender, EventArgs e)
        {
            this.AddLogEntry("Sending test message using DirectSend()");

            ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();
            message.From.Email = this.emailAddressTextbox.Text;
            message.To.Add(this.emailAddressTextbox.Text);
            message.Subject       = "This is a notification test.";
            message.BodyText.Text = "This is a notification test.";

            SmtpClient.DirectSend(message);

            this.AddLogEntry("Notification test message sent.");
        }
 public bool sendEmail(bool sendEmail)
 {
     "In send email".info();
     try
     {
         buildMessageObject();
         "about to send message".info();
         if (sendEmail)
         {
             SmtpClient.DirectSend(_message);
         }
         "message sent".info();
         return(true);
     }
     catch (Exception ex)
     {
         ex.log();
         return(false);
     }
 }
        private void sendMessageButton_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.fromEmailTextbox.Text;

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

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

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

            // We send the email directly without an SMTP server
            this.AddLogEntry("Sending message.");

            try
            {
                SmtpClient.DirectSend(message);

                this.AddLogEntry("Message sent successfully.");
            }
            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }
            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
Example #5
0
 /// <summary>
 /// Sends the message using the specified DNS servers to get mail exchange servers addresses.
 /// </summary>
 /// <param name="dnsServers">Servers to be used (in preference order).</param>
 /// <example>
 /// <code>
 /// C#
 ///
 /// SmtpMessage message = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 ///
 /// ServerCollection servers = new ServerCollection();
 /// servers.Add("ns1.dnsserver.com",53);
 /// servers.Add("ns2.dnsserver.com",53);
 ///
 /// message.DirectSend(servers);
 ///
 /// VB.NET
 ///
 /// Dim message As New SmtpMessage
 /// message.Subject = "Test"
 /// message.From = New Address("*****@*****.**","John Doe")
 /// message.To.Add("*****@*****.**","Mike Johns")
 /// message.BodyText.Text = "Hello this is a test!"
 ///
 /// Dim servers As New ServerCollection
 /// servers.Add("ns1.dnsserver.com",53)
 /// servers.Add("ns2.dnsserver.com",53)
 ///
 /// message.DirectSend(servers)
 ///
 /// JScript.NET
 ///
 /// var message:SmtpMessage = new SmtpMessage();
 /// message.Subject = "Test";
 /// message.From = new Address("*****@*****.**","John Doe");
 /// message.To.Add("*****@*****.**","Mike Johns");
 /// message.BodyText.Text = "Hello this is a test!";
 ///
 /// var servers:ServerCollection = new ServerCollection();
 /// servers.Add("ns1.dnsserver.com",53);
 /// servers.Add("ns2.dnsserver.com",53);
 ///
 /// message.DirectSend(servers);
 /// </code>
 /// </example>
 public string DirectSend(ServerCollection dnsServers)
 {
     return(SmtpClient.DirectSend(this, dnsServers));
 }