'(where DMAPI is the root namespace for the web service reference) Private Sub SendFile(sUsr as string, sPwd as string) Dim oFS As New System.IO.FileStream("C:\testfile.pdf", IO.FileMode.Open, IO.FileAccess.Read) Dim bFile(oFS.Length - 1) As Byte Try oFS.Read(bFile, 0, oFS.Length) Finally oFS.Close() End Try Dim oService As New DMAPI.DMWS() Dim oSAH As New DMAPI.ServiceAuthHeader() oSAH.Username = sUsr oSAH.Password = sPwd Dim oMailing As New DMAPI.Mailing Dim oAddress As New DMAPI.Address() oMailing.MailingDescription = "Description" oMailing.IsBlackAndWhite = False oMailing.IsDuplex = False 'AddressNameFormat - defines how the name will be formatted on the address of the letter '(aimed at mailings where the name fields may be used as part of a full mail-merge) ' "T"=[Title] [Firstname] [Surname] ' "S"=[Title] [Surname] ' "F"=[Firstname] [Surname] ' "D"=[Fullname] oMailing.AddressNameFormat = "T" ' With oAddress .Title = "NameTitle" .FirstName = "FirstName" .Surname = "Surname" .JobTitle = "JobTitle" .FullName = "FullName" .Address1 = "Address1" .Address2 = "Address2" .Address3 = "Address3" .Address4 = "Address4" .Address5 = "Address5" End With 'add address to mailing ReDim oMailing.Addresses(0) oMailing.Addresses.SetValue(oAddress, oMailing.Addresses.Count - 1) Dim oTemplate As New DMAPI.Template With oTemplate .FileData = bFile .FileName = "tsftfile.pdf" .TemplateName = "TemplateName" .AddressedDocument = True End With 'add template to mailing ReDim oMailing.Templates(0) oMailing.Templates.SetValue(oTemplate, oMailing.Templates.Count - 1) 'Save mailing Dim oMailingResult As DMAPI.MailingResult = oService.SaveMailing(oSAH, oMailing) If Not oMailingResult.Success Then Throw New Exception(String.Format("Mailing error: {0}", oMailingResult.FailureMessage)) 'Create a proof of the mailing Dim oProof As DMAPI.Proof = oService.GetProof(oSAH, oMailingResult.MailingGUID, True) Dim iSecondCount As Integer = 0 'Loop for 3 mins waiting for a proof While (iSecondCount < 180) AndAlso oProof.Success AndAlso Not oProof.ProofReady 'Sleep for 5 seconds System.Threading.Thread.Sleep(1000) oProof = oService.GetProof(oSAH, oMailingResult.MailingGUID, True) iSecondCount += 1 End While If Not oProof.Success Or Not oProof.ProofReady Then Throw New Exception("Proof not ready within 3 mins") 'Place the order Dim oOrderResult As DMAPI.PlaceOrderResult = oService.PlaceOrder(oSAH, oMailingResult.MailingGUID, "") If Not oOrderResult.Success Then Throw New Exception(String.Format("PlaceOrder error: {0}", oOrderResult.FailureMessage)) End Sub