I am trying to send an email using the Soap API but always get the following error:

Additional information: Must specify a {http://www.w3.org/2001/XMLSchema-instance}type attribute value for the {urn:enterprise.soap.sforce.com}messages element

The Soap API itself works like a charm, I can query and insert objects with no problem.

The code is pretty basic, but here it is:

EmailFileAttachment efa = new EmailFileAttachment();
efa.body = File.ReadAllBytes(_outputFile.ToString());
efa.fileName = "Ticket";
efa.inline = false;

var attachements = new EmailFileAttachment[1];
attachements[0] = efa;

var mail = new SingleEmailMessage();
mail.orgWideEmailAddressId = _orgWideEmailAddress;
mail.fileAttachments = attachements;
mail.subject = "Registration Mail";
mail.toAddresses = new[] {member.Email};
mail.htmlBody = "Test";

_sForceRef.sendEmail(new []{mail});

I have of course also tried it without the attachment, but no change there.

The code of the sendEmail function from the Web Reference looks as followed:

public SendEmailResult[] sendEmail([XmlElementAttribute("messages")] SingleEmailMessage[] messages) {
        object[] results = this.Invoke("sendEmail", new object[] {
        return ((SendEmailResult[])(results[0]));

Additionally, I have found the following link where it is suggested, that I'd need to set the type attribute in the XML whether it's a SingleEmailMessage or a MassEmailMessage - but I have no idea how exactly I could achieve that and did find nothing looking for that.

Other things I've tried are to use new SingleEmailMessage[] {mail} instead of just new []{mail} and to set the Type attribute of the XmlElementAttribute like so: XmlElementAttribute("messages", typeof(SingleEmailMessage)), but to no avail.

  • I think you just have to change new []{mail} to a typed list. I'm not sure of the syntax but maybe new List<SingleEmailMessage>{mail} would work instead? – Adrian Larson May 9 '17 at 13:28
  • @AdrianLarson sendEmail only accepts an array, so I tried new SingleEmailMessage[] {mail}, but no change there as well :/ – Andreas Steiner May 9 '17 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.