EmbeddedMailObjectsCollection Class
Collapse the table of content
Expand the table of content

EmbeddedMailObjectsCollection Class


Represents an ordered set of EmbeddedMailObject objects.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)


public sealed class EmbeddedMailObjectsCollection : CollectionBase


Initializes a new instance of the EmbeddedMailObjectsCollection class.


Gets or sets the number of elements that the CollectionBase can contain.(Inherited from CollectionBase.)


Gets the number of elements contained in the CollectionBase instance. This property cannot be overridden.(Inherited from CollectionBase.)


Returns a specific element of a EmbeddedMailObjectsCollection, identified by its position.


Adds an EmbeddedMailObject to the end of the EmbeddedMailObjectsCollection collection.


Removes all objects from the CollectionBase instance. This method cannot be overridden.(Inherited from CollectionBase.)


Determines whether the EmbeddedMailObjectsCollection contains a specific EmbeddedMailObject.

System_CAPS_pubmethodCopyTo(EmbeddedMailObject[], Int32)

Copies the collection objects to a one-dimensional Array instance beginning at the specified index in the array.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Returns an enumerator that iterates through the CollectionBase instance.(Inherited from CollectionBase.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Determines the index of a specific EmbeddedMailObject in the EmbeddedMailObjectsCollection.

System_CAPS_pubmethodInsert(Int32, EmbeddedMailObject)

Inserts an EmbeddedMailObject into the EmbeddedMailObjectsCollection object at the specified index position.


Removes the first occurrence of the specified EmbeddedMailObject from the EmbeddedMailObjectsCollection.


Removes the element at the specified index of the CollectionBase instance. This method is not overridable.(Inherited from CollectionBase.)


Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection.CopyTo(Array, Int32)

Copies the entire CollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.(Inherited from CollectionBase.)


Adds an object to the end of the CollectionBase.(Inherited from CollectionBase.)


Determines whether the CollectionBase contains a specific element.(Inherited from CollectionBase.)


Searches for the specified Object and returns the zero-based index of the first occurrence within the entire CollectionBase.(Inherited from CollectionBase.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.Insert(Int32, Object)

Inserts an element into the CollectionBase at the specified index.(Inherited from CollectionBase.)


Removes the first occurrence of a specific object from the CollectionBase.(Inherited from CollectionBase.)


Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)


Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)


Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)


Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

The EmbeddedMailObjectsCollection stores references to items that will be embedded in an e-mail message. The embedded items can be image files such as company logos. The EmbeddedMailObjectsCollection is used by the EmbeddedObjects property of the MailDefinition object.

E-mail messages that allow embedded objects are configurable in the following Web controls by setting their MailDefinition properties declaratively:


The values in the EmbeddedMailObject and EmbeddedMailObjectsCollection objects are not stored in view state. This protects against malicious users discovering path information for your server.

The following code example demonstrates an ASP.NET page that uses a ChangePassword Web control, and includes an event handler for the SendingMail event named SendingMail. The code example assumes that the ASP.NET Web site has been configured to use ASP.NET membership and Forms authentication, and that a user has been created whose name and password are known to you. For more information, see How to: Implement Simple Forms Authentication.

If the password change succeeds, the code in the SendingMail event handler attempts to send an e-mail message to the user to confirm the change. SMTP must already be configured on the server in order for this code example to work. For information about how to configure an SMTP server, see NIB: How to: Install and Configure SMTP Virtual Servers in IIS 6.0. For the purposes of this example, it is not necessary to configure an SMTP server; the example is constructed to test for a failure to send an e-mail message.

If a mail server is not configured correctly or some other error occurs and the e-mail message cannot be sent, the SendMailError function is called. A message is displayed to the user. In addition, an event is logged to the Windows Application event log with the assumption that an event source named MySamplesSite already exists. See the code example below to create the specified event source. For more information about creating an event source, see Server Event Handling in ASP.NET Web Forms Pages. The Handled property of the SendMailErrorEventArgs object is set to true to indicate that the error has been handled.

Use the following code example if you need to programmatically add the event source named MySamplesSite to your Application log. This event source must exist in order for the first code example to work correctly. The following code example requires Administrator privileges.

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;


namespace CreateEventSource
    class Program
        static void Main(string[] args)

                // Create the source, if it does not already exist.
                if (!EventLog.SourceExists("MySamplesSite"))
                    EventLog.CreateEventSource("MySamplesSite", "Application");
                    Console.WriteLine("Creating Event Source");

                // Create an EventLog instance and assign its source.
                EventLog myLog = new EventLog();
                myLog.Source = "MySamplesSite";

                // Write an informational entry to the event log.    
                myLog.WriteEntry("Testing writing to event log.");

                Console.WriteLine("Message written to event log.");
            catch (Exception e)
                Console.WriteLine("{0}", e.ToString());

The following example code can be used as the ChangePasswordMail.htm file for the preceding example code.

System_CAPS_security Security Note

Sending user account names or passwords in e-mail is a potential security threat. E-mail messages are typically sent in plain text and can be read by special network "sniffing" applications. To improve security, use the mitigations that are described in Securing Login Controls.


  <h1>Your password for the account named &quot;<%Username%>&quot; has changed.</h1>

  If you did not initiate this change, please call 1-206-555-0100.

  <a href="http://www.contoso.com/login.aspx">
    <img src="cid:LoginGif" alt="Log In" />

  Please read our attached Privacy Notice.


.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft