Documentation > CMS Template API Library > Asset > SaveEmailAttachment(String,EmailAttachment)

SaveEmailAttachment

Saves an email attachment to an asset. This function has been designed to run under the SmtpImportContext and will throw a contract error if called from the wrong context. Once the attachment has been saved it is treated like an uploadedFile.

public System.Boolean SaveEmailAttachment(String,EmailAttachment)


Returns

True if success, false if failure.

Parameters

NameDescriptionType
fieldName The field name where this will be stored. System.String
attachment The EmailAttachement that will be saved intot he asset. CrownPeak.CMSAPI.EmailAttachment

Code Example

C#

Sample:
foreach (EmailAttachment attachment in context.EmailAttachments)
{
  string fieldName = "";
  switch (attachment.Label)
  {
    case "Original":
      fieldName = "original_image";
      break;

    case "Thumbnail-50":
      fieldName = "thumbnail50_image";
      break;

    case "Thumbnail-25":
      fieldName = "thumbnail25_image";
      break;
  }
  if (!string.IsNullOrWhiteSpace(fieldName))
  {
    asset.SaveEmailAttachment(fieldName, attachment);
  }
}    

Connect with Crownpeak