Search code examples
vbscriptcdo.message

Giving an attachment a name when sending it with VBscript


set cdoConfig = CreateObject("CDO.Configuration")
with cdoConfig.Fields
  .Item(cdoSendUsingMethod) = cdoSendUsingPort
  .Item(cdoSMTPServer) = "localhost"
  .Item(cdoSMTPAuthenticate) = 1
  .Item(cdoSendUsername) = "[email protected]"
  .Item(cdoSendPassword) = "password"
  .Update
end with
set cdoMessage = CreateObject("CDO.Message")
with cdomessage
set .Configuration = cdoConfig
  .From = "[email protected]"
  .To = email
  .Subject = subject
  .HTMLBody = message
  .AddAttachment "c:/i/report.pdf"
  .Send
end with
set cdomessage = nothing
set cdoconfig = nothing

Everything sends find, but the recipient gets the message as "Untitled Attachment 000X.pdf"

How do I give the attachment a name?


Solution

  • I have something like this. But never tried.

    'With cdomessage
    
    .AddAttachment "c:/i/report.pdf"
    .Attachments(1).Fields.Item("urn:schemas:mailheader:content-disposition") ="attachment;filename=" & NEWNAME
    .Attachments(1).Fields.Update
    
    'End With