Create an Email

Use SOAP API to create an email message. By using the SOAP API to create your email, you can integrate the process of creating an email with your system or development environment. This allows you to create email messages outside of Marketing Cloud Engagement.

Marketing Cloud Engagement has a new model for storing, finding, managing, creating, sharing, and distributing all content-related objects. Access the objects created with the new Content Builder tools using the REST API. Your existing SOAP API integrations only function with the Classic tools.

Note

Code Examples 

These code examples show how to create an email.

Sample .NET Code 

1// Create e-mail object
2            // We do this separately so that the results of the e-mail creation can
3            // be reported clearly back to caller.
4            Email email = new Email();
5            email.Subject = "Check out my way cool email";
6            email.Name = "Dynamic Email_" + DateTime.Now.ToShortTimeString();
7            email.HTMLBody = "<center>##Way Cool Email</center>";
8            email.TextBody = "Way Cool Email";
9            email.CharacterSet = "iso-8859-1";
10            email.CategoryID = 556442;  //This is the Folder where the email is stored.
11                                          //Get the Category ID by hovering over the folder in the account and looking at the CID= in the URL at the bottom.
12            email.CategoryIDSpecified = true;
13            CreateResult[] results = proxy.Create(new CreateOptions(), new APIObject[] { email }, out requestID, out status);

Sample Java Code (Axis 1.4) 

1public void testCreateEmail() throws RemoteException {
2        Email email = new Email();
3        email.setStatus("Test Email with Content Areas");
4        email.setName("Test Email with Content Areas");
5        email.setSubject("email subject line");
6        email.setCharacterSet("UTF-8");
7        email.setHTMLBody("<html><body><custom type=\"content\" name=\"cell1\"></body></html>");
8        ContentArea contentArea = new ContentArea();
9        contentArea.setKey("cell1");
10        contentArea.setContent("%%[ var @maintenance_items, @recallrows, @recallstring , @MOP_DESC1]%%\n" +
11                "%%[if trim(MOP_DESC1) != \"\" then]%%%%MOP_DESC1%%");
12        email.setContentAreas(new ContentArea[]{contentArea});
13        Soap stub = init();
14          //  email.setIsHTMLPaste();
15        CreateRequest createRequest = new CreateRequest();
16        createRequest.setObjects(new APIObject[]{email});
17        createRequest.setOptions(new CreateOptions());
18        CreateResponse results = stub.create(createRequest);
19        System.out.println("results :: " + results.getOverallStatus());
20    }

Sample Ruby Code 

1require 'rubygems'
2gem 'soap4r'
3require 'soap/wsdlDriver'
4require 'soap/header/simplehandler'
5require 'defaultDriver.rb'
6require 'authStub.rb'
7<%#Async create options%>
8<%#options = CreateOptions.new(nil,nil,nil,nil,nil,nil,nil,nil,'Asynchronous')%>
9options = nil
10footer = "<table cellpadding='2' cellspacing='0' width='600' border='0' align='center'><tr><td valign='top' align='left' style='line-height: 16px;'><p><font face='verdana' size='1' color='#777777'>This email was sent to:  <b>%%emailaddr%%</b><br /><a href='%%subscription_center_url%%' alias='Manage Subscriptions'>Manage Subscriptions</a> | <a href='%%profile_center_url%%' alias='Update Profile'>Update Profile</a> | <a href='%%unsub_center_url%%' alias='Unsubscribe'>One-Click Unsubscribe</a></p><p>This email was sent by: <b>%%Member_Busname%%</b><br />%%Member_Addr%% %%Member_City%%, %%Member_State%% %%Member_PostalCode%% %%Member_Country%%</p><p>We respect your right to privacy - <a href='http://email.exacttarget.com/ETWeb/company.aspx?id=80' alias='View Privacy Policy' style='color: #0000ff'>view our policy</a></p></font></td><td width='145' align='right' valign='center'><a href='http://www.exacttarget.com' title='This email is Powered By Marketing Cloud Engagement' alias='Powered By'><img src='http://email.exacttarget.com/images/Powered_By_1206.jpg' width='124' height='55' alt='This email is Powered By Marketing Cloud Engagement' border='0' /></a></td></tr></table>"
11Params = {
12  :CustomerKey => "API-Test-9",
13  :Name => "API-Test-9",
14  :ID => nil,
15  :ClonedFromID => 2723760,
16  :Subject => "Thank you for subscribing",
17  :HTMLBody => "<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" style=\"border-top: 1px solid #CCC; border-bottom: 1px solid #CCC; padding: 16px 0;\"><tbody><tr><td align=\"left\"><p>Now is the time for all good men to come to the aid of their country.</p><p>Now is the time for all good men to come to the aid of their country.</p><p>Now is the time for all good men to come to the aid of their country.</p><p>Now is the time for all good men to come to the aid of their country.</p><p>Now is the time for all good men to come to the aid of their country.</p></td></tr><tr><td align=\"left\"><custom type=\"content\" name=\"cell2\"></custom></td></tr></tbody></table><custom name=\"opencounter\" type=\"tracking\"></custom>" + footer
18}
19emailObj = Email.new(nil,nil,nil,nil,nil,Params[:ID],nil,Params[:CustomerKey],nil,nil,Params[:Name],nil,nil,Params[:HTMLBody],Params[:HTMLBody].gsub(/<\/?[^>]*>/,""),nil,Params[:Subject],nil,1)
20apiObj = emailObj
21resp = $driver.create(CreateRequest.new(options,[*apiObj]))

Sample SOAP Envelope 

1<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
2   <soap:Header>
3      <wsa:Action>Create</wsa:Action>
4      <wsa:MessageID>urn:uuid:0caa9e7d-bd29-4dab-b268-668343be00bd</wsa:MessageID>
5      <wsa:ReplyTo>
6         <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
7      </wsa:ReplyTo>
8      <wsa:To>https://YOUR_SUBDOMAIN.soap.marketingcloudapis.com/Service.asmx</wsa:To>
9      <wsse:Security soap:mustUnderstand="1">
10         <wsse:UsernameToken wsu:Id="SecurityToken-8ab9d52b-cf40-465b-9464-1a7c7f000460">
11            <wsse:Username>XXXX</wsse:Username>
12            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXX</wsse:Password>
13         </wsse:UsernameToken>
14      </wsse:Security>
15   </soap:Header>
16   <soap:Body>
17      <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
18         <Options/>
19         <Objects xsi:type="Email">
20            <Client>
21                <ID>12345678</ID>
22                <UserID>12345678</UserID>
23            </Client>
24            <ObjectID xsi:nil="true"/>
25            <Name>Test Email with Content Areas</Name>
26            <Description>Description</Description>
27            <HTMLBody>Example HTML Body</HTMLBody>
28            <Subject>Test Subject</Subject>
29            <EmailType>HTML</EmailType>
30            <IsHTMLPaste>true</IsHTMLPaste>
31         </Objects>
32      </CreateRequest>
33   </soap:Body>

If you want to include dynamic content in your email messages, use AMPscript to dynamically assign content. You can’t create content areas containing dynamic script via the SOAP API.

Related Items