Ejemplo n.º 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;
		}