How to Convert an Email MSG File to a PNG Image Array using Go

Cloudmersive
2 min readNov 17, 2022

--

Much like converting MSG to PDF, converting MSG to PNG allows you to store email related objects in a way that protects their exact formatting aesthetic on someone else’s operating system. It’s also a great way to store lightweight copies of important emails (there are several other use cases beyond that as well which I will not enumerate here).

Our MSG to PNG Array API makes it super easy to perform this conversion at scale; all you need to do is follow brief instructions below to structure your API call using ready-to-run Golang code examples. The great thing is that it’s free to use! All you need is a free-tier Cloudmersive API key, which you can get by registering a free account on our website (free-tier API keys provide a limit of 800 API calls per month & no additional commitments).

Calling this API is a one-step process. Simply include the examples below in your file, and copy our API key as a string into the appropriate header. After that, configure your file input, and you’re good to go:

package main

import (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)

func main() {

url := "https://api.cloudmersive.com/convert/msg/to/png"
method := "POST"

payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
file, errFile1 := os.Open("/path/to/file")
defer file.Close()
part1,
errFile1 := writer.CreateFormFile("inputFile",filepath.Base("/path/to/file"))
_, errFile1 = io.Copy(part1, file)
if errFile1 != nil {
fmt.Println(errFile1)
return
}
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}


client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)

if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "multipart/form-data")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")

req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

Simple & easy!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet