Allow inline attachments in send message API #1479
Replies: 8 comments
-
This would be a nice feature to have but would probably require a fair bit of rewriting to incorporate it because of the various client libraries. |
Beta Was this translation helpful? Give feedback.
-
Ok, got it, thanks! Will be use /send/raw instead. |
Beta Was this translation helpful? Give feedback.
-
No worries, if you could share your code when it is working, I'm sure it will be handy for whoever wants to add this feature. |
Beta Was this translation helpful? Give feedback.
-
I very want to help, but actually, i'm Java/Kotlin guy, Ruby is like petroglyphs for me. |
Beta Was this translation helpful? Give feedback.
-
I hear that! I meant if you're able to share how you use the /send/raw endpoint, it will be useful information even if its in a different programming language! |
Beta Was this translation helpful? Give feedback.
-
Oh, now i see, sorry :) @Service
class PostalApiSender(private val restTemplate: RestTemplate,
private val postalProperties: PostalProperties) : EmailSender() {
val logger = getLogger<PostalApiSender>()
override fun send(emailMessage: EmailMessage): Boolean {
val session: Session? = null
val message = MimeMessage(session)
try {
val helper = MimeMessageHelper(message, true, "utf-8")
helper.setFrom(emailMessage.from)
helper.setTo(emailMessage.to)
if (emailMessage.replyTo != null) {
helper.setReplyTo(emailMessage.replyTo!!)
}
helper.setSubject(emailMessage.subject)
if (emailMessage.html != null) {
helper.setText(emailMessage.html!!, true)
}
if (emailMessage.logoPath != null) {
helper.addInline("inlineLogo", ClassPathResource(emailMessage.logoPath))
}
val os = ByteArrayOutputStream()
message.writeTo(os)
val rawMessageRequest = RawMessageRequest(
emailMessage.from,
listOf(emailMessage.to),
Base64.getEncoder().encodeToString(os.toByteArray())
)
val response = restTemplate.postForObject<SendMessageResponse>("/api/v1/send/raw", rawMessageRequest)!!
if (response.status == "error") {
logger.error("Error sending email via Postal API", SendPostalEmailMessageException(response.data.message
?: "Message not provided"))
return false
}
return true
} catch (e: Exception) {
logger.error("Error sending message", e)
return false
}
}
}
It's shortened version of my code, i have avoid some logic just to show an idea. Hope it helps somebody |
Beta Was this translation helpful? Give feedback.
-
I forked an existing java client for Postal Api to add support for embedded images if anyone is interested. It's using the |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi!
Seems it's no way to send messages by send API with inline attachments
I would like to send message with logo, that i can refer by cid:logo in html part. According to https://sendgrid.com/blog/embedding-images-emails-facts/ it's most reliable way to embed images to email.
Of course i can send by API as raw message, but it's really hard to prepare message in such form.
AFAIK Mailer 3.0 support inline attachments, can you also add that support ?
Beta Was this translation helpful? Give feedback.
All reactions