Sample code for 30+ languages & platforms
Go

Attach Email as message/rfc822 sub-part to an Email

See more Email Object Examples

Demonstrates how to add attach a message/rfc822 email to another email.

Chilkat Go Downloads

Go
    success := false

    // In this example, we'll attach an email loaded from a .eml file to a new email.

    var emlBytes []byte

    fac := chilkat.NewFileAccess()
    emlBytes = fac.ReadEntireFile("qa_data/eml/simple.eml")

    email := chilkat.NewEmail()
    email.SetSubject("This is a test email with an attached email.")
    email.SetBody("Test with attached email.")
    email.AddTo("Joe","joe@example.com")
    email.SetFrom("mary@example.com")

    success = email.AttachMessage(emlBytes)

    fmt.Println(*email.GetMime())

    // ----------------------------------------------------------------------
    // Alternatively, we could do this:
    emailToBeAttached := chilkat.NewEmail()
    success = emailToBeAttached.LoadEml("qa_data/eml/simple.eml")

    email2 := chilkat.NewEmail()
    email2.SetSubject("This is a test email with an attached email.")
    email2.SetBody("Test with attached email.")
    email2.AddTo("Joe","joe@example.com")
    email2.SetFrom("mary@example.com")

    var emlBytes2 []byte
    emlBytes2 = emailToBeAttached.GetMimeBinary()
    success = email2.AttachMessage(emlBytes2)

    fmt.Println("----")

    fmt.Println(*email2.GetMime())

    fac.DisposeFileAccess()
    email.DisposeEmail()
    emailToBeAttached.DisposeEmail()
    email2.DisposeEmail()