-1

I am using Gmail SMTP server to send out a .mht file. once send out, i am getting a lot of attachemnts and the .mht file were loading in the email body (from yahoo mail). Instead in outlook, i am getting it as a mail attachements. VB script used for this :

Set objMessage = CreateObject("CDO.Message")
objMessage.HTMLBody = "<h1>Matrikon AM</h1>" 
objMessage.Subject = "Test 1 -Blank" 
objMessage.From = "xxxxx@gmail.com" 
objMessage.To = "xxxxx@yahoo.com" 
objMessage.TextBody = "From b.vbs"
objMessage.AddAttachment "c:\xxxxxxx\A1.mht" 
objMessage.Send

I had some quick search online that "ContentMediaType" have to be define somewhere since the file extension is .mht. Need help on this as i could not find a way to define the content-type. My issue were exactly like mentioned in "https://stackoverflow.com/questions/15976836/modifying-the-content-type-of-an-attachment-in-a-cdo-message-object"

thanks.

Community
  • 1
  • 1
ambani
  • 1
  • 1
  • Can I know what should I add in my VBsccript in order to get .mht attachement go through? As I aware I need to defined the "content-type" somewhere.. – ambani Mar 24 '15 at 06:17

1 Answers1

0

This is from Help.

urn:schemas:mailheader: Namespace

The urn:schemas:mailheader: namespace defines fields that contain Internet standard message header values. Each field value (with a few exceptions) is stored as US-ASCII characters and is identical to the ASCII string found in the message stream. Non US-ASCII characters are encoded according to the RFC 1522 specification. No conversion is performed when the property value is set or updated. An application that sets the raw message header property must RFC 1522-encode non US-ASCII characters or the header value will be corrupted.

String constants are provided in the C++ header file cdosysstr.h and type library (cdoMailHeader module) for each field name. You can use these constants when referring to the fields to avoid typos and extra typing.

Example The following example demonstrates use of the fields in the urn:schemas:mailheader: namespace. First, RFC 822 headers are added for a message. Next, body parts are added and the MIME headers set manually.

This code is for illustrative purposes only.

Copy Code

Dim iMsg as New CDO.Message
Dim Flds as ADODB.Fields
With iMsg
  .To   = """Someone"" <example@example.com>"
  .From = """Me"" <example@example.com>"
  .Subject = "Here is a sample message"

   ' Now set some custom mail headers using the raw fields collection
   Set Flds = .Fields
   With Flds
     .Item("urn:schemas:mailheader:X-Mailer")  = "Microsoft CDO for Windows 2000"
      ' I add a custom header here
     .Item("urn:schemas:mailheader:Myheader")= "some value"
     .Update
     .Resync
   End With ' Flds
End With ' iMsg
' Create a multipart/alternative (HTML) message below

Dim iBp as CDO.IBodyPart
Dim iBp2 as CDO.IBodyPart

Set iBp = iMsg   '  get IBodyPart on Message object

Set Flds = iBp.Fields
Flds("urn:schemas:mailheader:content-type") = "multipart/alternative"
Flds.Update

Set iBp2 = iBp.AddBodyPart
Set Flds = iBp2.Fields
Flds("urn:schemas:mailheader:content-type") = "text/plain"
Flds("urn:schemas:mailheader:content-transfer-encoding") = "quoted-printable"
Flds.Update

Dim Stm as ADODB.Stream
Set Stm = iBp2.GetDecodedContentStream
Stm.WriteText "This is a test", stWriteLine
Stm.Flush

Set iBp2 = iBp.AddBodyPart
Set Flds = iBp2.Fields
Flds("urn:schemas:mailheader:content-type") = "text/html"
Flds("urn:schemas:mailheader:content-transfer-encoding") = "quoted-printable"
Flds.Update

Set Stm = iBp2.GetDecodedContentStream
Stm.WriteText "This is a <i>test</i>", stWriteLine
Stm.Flush

iMsg.Send
Serenity
  • 34
  • 3
  • Thanks for the reply. As I'm very new to this Vbscript, unsure about this. Could you let me know if I replace my existing VBscript with your code, will this work well with .mht attachments? Do I need to edit the code? Then when I run it, It gives error as " Line: 1 char:10 Error: Expected end of statement. " Could anyone help me with the script? – ambani Mar 24 '15 at 06:06