Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested multipart data is not supported #48

Open
j4nos opened this issue Nov 20, 2020 · 5 comments
Open

Nested multipart data is not supported #48

j4nos opened this issue Nov 20, 2020 · 5 comments

Comments

@j4nos
Copy link

j4nos commented Nov 20, 2020

I am attaching image as suggested in docs, but get this error, what is wrong, how to do it differently?

let bytes: [UInt8] = Array(buffer: body)
var bytesBuffer = ByteBufferAllocator().buffer(capacity: bytes.count)
bytesBuffer.writeBytes(bytes)
let file = File.init(data: bytesBuffer, filename: "\(ti.eventId)_0.cover.jpg")

//let file = File(data: img, filename: "\(ti.eventId)_0.cover.jpg")
let mgm = MailgunMessage(from: emailFrom, to: [u.invoiceDetails!.email], replyTo: nil, cc: nil, bcc: nil, subject: e.welcomeEmailSubject ?? "Welcome", text: text, html: nil, attachments: [file], inline: nil)
print("Welcome message will be sent \(u.name)")
fflush(stdout)
return request.mailgun(.myApp1).send(mgm).map { (cr) -> (String) in
    print("Welcome message sent: \(u.name)")
    fflush(stdout)
    return "Welcome message sent \(u.name)"
}
@Preemoz
Copy link

Preemoz commented Jan 28, 2021

I would like to send a PDF attachment and am also getting the error mentioned in the title. I first make an API call to a 3rd party service that returns a Data object, then I follow the docs and convert it to ByteArray and use it to create a File. I'm able to create a PDF document and show it inside a PDFView an iOS app, which means the data is not corrupt. Is there an error in the docs, or am I missing something?

@pointum
Copy link

pointum commented Apr 30, 2021

Had the same issue. If I understood the Mailgun API docs correctly, the attachment option expects a single file, not an array of files:

attachment: File attachment. You can post multiple attachment values.

So to attach multiple files you need to provide several attachment options, not a single option with an array of files.

I changed code in MailgunMessage from:

public let attachment: [File]?

to

public let attachment: File?

Then I was able to send and receive an email with an attached file.

@Andrewangeta
Copy link
Member

@madsodgaard would the new multipart-kit address this original issue?

@0xTim
Copy link
Member

0xTim commented Apr 30, 2021

It will do once the nested data PR is merged

@Steven4294
Copy link

getting the same issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants