Sub SendEnhancedEmailWithAttachment() 'Test of simple Enhanced e-mail with HTML document and a pdf attachment. Dim EM As EMsgAPIJobSubmit201101.JobSubmitService = New EMsgAPIJobSubmit201101.JobSubmitService Dim request As EMsgAPIJobSubmit201101.Request = New EMsgAPIJobSubmit201101.Request Dim authentication As EMsgAPIJobSubmit201101.RequestAuthentication = New EMsgAPIJobSubmit201101.RequestAuthentication Dim xddsauth As EMsgAPIJobSubmit201101.XDDSAuthType = New EMsgAPIJobSubmit201101.XDDSAuthType Dim jobrequest As EMsgAPIJobSubmit201101.JobSubmitRequest = New EMsgAPIJobSubmit201101.JobSubmitRequest Dim uid As EMsgAPIJobSubmit201101.UIDType = New EMsgAPIJobSubmit201101.UIDType ' Set the URL EM.Url = GetRequestUrl() ' Build the SOAP Header uid.Value = API_Demo.txtUserID.Text xddsauth.RequesterID = uid 'UID xddsauth.Password = API_Demo.txtPassword.Text 'Password authentication.Item = xddsauth request.Authentication = authentication request.ReceiverKey = GetRequestUrl() 'request.ResultRequired = EMsgAPIJobSubmit201101.RequiredType.yes request.RequestID = "Test" EM.RequestValue = request If API_Demo.chkUseProxyTrace.Checked Then EM.Proxy = New System.Net.WebProxy("http://localhost:8080") End If ' Create Message Object Dim message As EMsgAPIJobSubmit201101.MessageType() ReDim message(1) message(0) = New EMsgAPIJobSubmit201101.MessageType Dim doctype As EMsgAPIJobSubmit201101.DocumentType = New EMsgAPIJobSubmit201101.DocumentType Dim joboptions As EMsgAPIJobSubmit201101.JobOptionsType = New EMsgAPIJobSubmit201101.JobOptionsType Dim CustomerReference As New EMsgAPIJobSubmit201101.EncodableStringType CustomerReference.Value = "EM MessageREACH Job" joboptions.CustomerReference = CustomerReference joboptions.BillingCode = CustomerReference Dim emailOptions As EMsgAPIJobSubmit201101.EnhancedEmailOptionsType = New EMsgAPIJobSubmit201101.EnhancedEmailOptionsType Dim subject As New EMsgAPIJobSubmit201101.EncodableStringType subject.Value = "Hello John Doe Premiere Connect Test" emailOptions.FromDisplayName = "Premiere" emailOptions.ReplyTo = "ReplyEmail@pgi.com" ' emailOptions.ExpirationDays = 90 ' emailOptions.ExpirationDaysSpecified = True emailOptions.Subject = subject emailOptions.HTMLOpenTracking = EMsgAPIJobSubmit201101.HTMLOpenTrackingType.top emailOptions.HTMLOpenTrackingSpecified = True joboptions.EnhancedEmailOptions = emailOptions message(0).JobOptions = joboptions joboptions = Nothing emailOptions = Nothing Dim document As EMsgAPIJobSubmit201101.DocumentType() ReDim document(2) document(0) = New EMsgAPIJobSubmit201101.DocumentType 'this will be a simple text doc document(1) = New EMsgAPIJobSubmit201101.DocumentType 'this will be an HTML document document(2) = New EMsgAPIJobSubmit201101.DocumentType Dim documentdata As EMsgAPIJobSubmit201101.DocDataType = New EMsgAPIJobSubmit201101.DocDataType documentdata.format = EMsgAPIJobSubmit201101.DocEncodingFormat.text documentdata.Value = "Hi John Doe, " & vbCrLf & "This is a generic message from Tammy please reply" ' Set Document 0 - Text Body Message document(0).Item = documentdata 'document(0).ItemElementName = EMsgAPIJobSubmit201101.ItemChoiceType1.DocData document(0).ItemElementName = EMsgAPIJobSubmit201101.ItemChoiceType.DocData document(0).DocType = "text" document(0).ref = "email_text" documentdata = Nothing ' USED TO READ IN CSV LIST AND HTML Dim inCSVFile As System.IO.StreamReader Dim fileData As String ' HTML Message Try 'inCSVFile = New System.IO.StreamReader("C:\Work\TestFiles\EnhancedEmailTestDoc.htm") inCSVFile = New System.IO.StreamReader("C:\Work\TestFiles\testHTML.html") fileData = inCSVFile.ReadToEnd() inCSVFile.Close() Catch exp As System.Exception ' Error creating stream or reading from it. System.Console.WriteLine("Error: {0}", exp.Message) Return End Try documentdata = New EMsgAPIJobSubmit201101.DocDataType documentdata.format = EMsgAPIJobSubmit201101.DocEncodingFormat.base64 documentdata.Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(fileData)) document(1).Item = documentdata documentdata = Nothing 'document(1).ItemElementName = EMsgAPIJobSubmit201101.ItemChoiceType1.DocData document(1).ItemElementName = EMsgAPIJobSubmit201101.ItemChoiceType.DocData document(1).DocType = "HTML" document(1).ref = "email_html_text" 'Document (2) - a pdf file attachment Dim attPdfFile As System.IO.FileStream Dim binaryData() As Byte Try attPdfFile = New System.IO.FileStream("C:\Work\TestFiles\PDF\test12.pdf", System.IO.FileMode.Open, IO.FileAccess.Read) ReDim binaryData(attPdfFile.Length) Dim bytesRead As Long = attPdfFile.Read(binaryData, 0, attPdfFile.Length) attPdfFile.Close() Catch exp As System.Exception ' Error creating stream or reading from it. 'System.Console.WriteLine("{0}", exp.Message) API_Demo.txtResult.Text = ("File Read Error: =" & exp.Message) Return End Try documentdata = New EMsgAPIJobSubmit201101.DocDataType documentdata.format = EMsgAPIJobSubmit201101.DocEncodingFormat.base64 Try documentdata.Value = System.Convert.ToBase64String(binaryData, 0, binaryData.Length) Catch ex As Exception API_Demo.txtResult.Text = ("Error converting to base64: =" & ex.Message) Return End Try 'document(2).ItemElementName = EMsgAPIJobSubmit201101.ItemChoiceType1.DocData document(2).ItemElementName = EMsgAPIJobSubmit201101.ItemChoiceType.DocData document(2).ref = "PdfAttachment" document(2).Item = documentdata Dim myFileName As EMsgAPIJobSubmit201101.EncodableStringType = New EMsgAPIJobSubmit201101.EncodableStringType myFileName.Value = "test12.pdf" document(0).Filename = myFileName document(2).DocType = "PDF" documentdata = Nothing Dim content() As EMsgAPIJobSubmit201101.ContentPartType Dim contentstype As EMsgAPIJobSubmit201101.ContentsType ReDim content(3) content(0) = New EMsgAPIJobSubmit201101.ContentPartType contentstype = New EMsgAPIJobSubmit201101.ContentsType contentstype.Part = content content(0).Item = "email_text" content(0).Treatment = EMsgAPIJobSubmit201101.TreatmentType.body content(0).TreatmentSpecified = True content(1) = New EMsgAPIJobSubmit201101.ContentPartType content(1).Item = "email_html_text" content(1).Treatment = EMsgAPIJobSubmit201101.TreatmentType.body content(1).TreatmentSpecified = True content(2) = New EMsgAPIJobSubmit201101.ContentPartType content(2).Item = "PdfAttachment" content(2).Treatment = EMsgAPIJobSubmit201101.TreatmentType.attachment content(2).TreatmentSpecified = True message(0).Contents = contentstype Dim reports As EMsgAPIJobSubmit201101.ReportOptionsType = New EMsgAPIJobSubmit201101.ReportOptionsType Dim deliveryreport As EMsgAPIJobSubmit201101.ReportOptionsTypeDeliveryReport = New EMsgAPIJobSubmit201101.ReportOptionsTypeDeliveryReport deliveryreport.DeliveryReportType = EMsgAPIJobSubmit201101.MainReportTypeEnum.detail reports.DeliveryReport = deliveryreport deliveryreport = Nothing message(0).Reports = reports reports = Nothing Dim table() As EMsgAPIJobSubmit201101.TableType ReDim table(0) table(0) = New EMsgAPIJobSubmit201101.TableType table(0).Item = "docREF_CSV" table(0).ref = "tblREF_CSV" Dim deliveryEmail() As EMsgAPIJobSubmit201101.InternetType ReDim deliveryEmail(2) deliveryEmail(0) = New EMsgAPIJobSubmit201101.InternetType deliveryEmail(0).Email = API_Demo.txtEmail.Text message(0).Destinations = deliveryEmail 'just one destination for now. jobrequest.Message = message jobrequest.DocumentSet = document Dim jobresult As EMsgAPIJobSubmit201101.JobSubmitResult = New EMsgAPIJobSubmit201101.JobSubmitResult EM.RequestValue = request Dim response As EMsgAPIJobSubmit201101.Response = New EMsgAPIJobSubmit201101.Response EM.ResponseValue = response Try jobresult = EM.JobSubmit(jobrequest) 'Catch ex As System.Web.Services.Protocols.SoapException Catch ex As Exception MsgBox(ex.Message) Return End Try Dim sJobNumber As String If (jobresult.Status.StatusCode = 0) And (jobresult.MessageResult(0).Status.StatusCode = 0) Then sJobNumber = jobresult.MessageResult(0).JobId.XDN & ":" & jobresult.MessageResult(0).JobId.MRN Debug.Write(EM.ResponseValue) API_Demo.txtResult.Text = ("Job Number=" & sJobNumber & vbCrLf & "Result=" & jobresult.Status.StatusCode & vbCrLf & jobresult.Status.StatusMessage) Else API_Demo.txtResult.Text = ("Error: Job Result=" & jobresult.Status.StatusCode & vbCrLf & jobresult.Status.StatusMessage & vbCrLf & "Message Result=" & jobresult.MessageResult(0).Status.StatusCode) End If End Sub