EmbeddedMailObject Class
Assembly: System.Web (in system.web.dll)
[TypeConverterAttribute(typeof(EmbeddedMailObjectTypeConverter))] public ref class EmbeddedMailObject sealed
/** @attribute TypeConverterAttribute(System.Web.UI.WebControls.EmbeddedMailObject+EmbeddedMailObjectTypeConverter) */ public final class EmbeddedMailObject
TypeConverterAttribute(System.Web.UI.WebControls.EmbeddedMailObject+EmbeddedMailObjectTypeConverter) public final class EmbeddedMailObject
Not applicable.
The EmbeddedMailObject represents an item to embed in a mail message. These embedded items can be image files such as company logos. Each embedded item is specified by an identifier and a path.
To ensure that an embedded object is displayed correctly within the e-mail message file, the following conditions must be met:
-
The mail message is in HTML format.
-
The item is an image file (.jpg, .gif, .bmp, and so on).
-
The HTML-formatted body file specified in the BodyFileName property contains a reference to the image file using the following syntax:
<img src="cid:identifier" alt="Alternate Text" />.
If an EmbeddedMailObject is added to a mail message and does not fulfill all of the requirements specified previously, it will most likely be displayed as an attachment in the mail message. If an item is referenced by an identifier in the mail message but not included as an embedded item, it will appear as a broken attachment when the mail is viewed.
The EmbeddedMailObjectsCollection stores a collection of EmbeddedMailObject objects for a single mail message. The EmbeddedMailObjectsCollection is used by the EmbeddedObjects property of the MailDefinition object to create the mail message.
Mail messages that allow embedded objects are configurable in the following Web controls by setting their MailDefinition properties declaratively:
Note: |
|---|
| 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 How to: Configure an SMTP Virtual Server. 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 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.
The following example code can be used as the ChangePasswordMail.htm file for the preceding example code.
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. |
<html>
<head><title></title></head>
<body>
<form>
<h1>Your password for the account named "<%Username%>" has changed.</h1>
<p>
If you did not initiate this change, please call 1-206-555-0100.
</p>
<p>
<a href="http://www.contoso.com/login.aspx">
<img src="cid:LoginGif" alt="Log In" />
</a>
</p>
<p>
Please read our attached Privacy Notice.
</p>
</form>
</body>
</html>
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
Reference
EmbeddedMailObject MembersSystem.Web.UI.WebControls Namespace
EmbeddedObjects
CreateUserWizard
CreateUserWizard.MailDefinition Property
CreateUserWizard.SendingMail Event
ChangePassword
ChangePassword.MailDefinition Property
ChangePassword.SendingMail Event
PasswordRecovery
MailDefinition
SendingMail
MailMessage
Note:
Security Note: