SMTP Code Example: Forwarding Email While Preserving Attachments
When forwarding an email programmatically using SMTP, attachments are not automatically preserved unless the message is forwarded correctly; this requires forwarding both the message body and the applicable message headers, specifically the MIME headers.
Private Sub Command1_Click()
POP1.MailServer = "server"
POP1.User = "me"
POP1.Password = "mypass"
POP1.Connect
POP1.MessageNumber = 2
POP1.Retrieve
SMTP1.MailServer = "server"
SMTP1.From = "me@server"
SMTP1.SendTo = "you@server"
Dim startsubj As Integer
Dim subjlen As Integer
startsubj = InStr(1, POP1.MessageHeaders, "Subject:")
subjlen = InStr(startsubj, POP1.MessageHeaders, vbCrLf)
SMTP1.Subject = "FW: " + Mid(POP1.MessageHeaders, startsubj, subjlen)
SMTP1.MessageText = POP1.MessageText
SMTP1.OtherHeaders = "MIME-Version: 1.0" + vbCrLf + _
"Content-Type: multipart/mixed; " + _
"boundary = ""----=_NextPart_000_0004_01C11B4B.B5239630""" + vbCrLf
SMTP1.Send
End Sub
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.