Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Email Attachment Using VBScript

1,009 views
Skip to first unread message

Robert Elliott

unread,
Dec 19, 2003, 5:32:19 PM12/19/03
to
Hello,

I am using the following code that I found on this message board to try and
send an email attachment. It is not working. Depending on what I change I
keep getting one of three different errors. I get an error stating that the
specified protocol is unknown; I also get an error that the system cannot
find the file specified when I know it is in the correct location; and I get
an error stating that the Object doesn't support this property or method:
'objMessage.AddAttachment'. Can anyone help with this? I was trying to run
this on my SMTP server directly.

Thanks,
Robbie

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "som...@somedomain.com"
objEmail.To = "acc...@domain.com"
objEmail.Subject = "test message"
objEmail.AddAttachment "d:\attachment.txt"
objEmail.textbody = "Text of message goes here"
objEmail.Send


Don Grover

unread,
Dec 19, 2003, 6:30:53 PM12/19/03
to
Robert this is working for me ok !

'******************************************************
'*** Send the message Using CDOSYS Win2k & Win2003 ****
'******************************************************
' CDO mail object
myMailServer = sEmailServer
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig
.Fields.Item(sch & "sendusing") = 2
.Fields.Item(sch & "smtpserverport") = iEmailPort
.Fields.Item(sch & "smtpserver") = myMailServer
'.Fields.Item(sch & "smtpauthenticate") = 1
'.Fields.Item(sch & "sendpassword") = "mypassword"
'.Fields.Item(sch & "sendusername") = "myusername"
.Fields.Update
End With

Set cdoMessage = CreateObject("CDO.Message")
Set cdoMessage.Configuration = cdoConfig

With cdoMessage
.From = sEmailAddFrom
.To = sConAdHocAddress
.BCC = sConEmailMonitor
.Subject = MakeValid(sSubject)
.TextBody = MakeValid(sBodyText)
If Trim(sUploadFile) <> "" Then
.AddAttachment "file://" & sTempPath & sUploadFile
ClearFilespec sTempPath & sUploadFile
End If
.Fields.Item("urn:schemas:mailheader:X-MSMail-Priority") = "High"
.Fields.Item("urn:schemas:mailheader:X-Priority") = 2
.Fields.Item("urn:schemas:mailheader:Sensitivity") =
"Company-Confidential"
.Fields.Item("urn:schemas:mailheader:Keywords") = "COKESHOP"
.Fields.Item("urn:schemas:mailheader:X-Message-Flag") = "Do not Forward"
.Fields.Update
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing


"Robert Elliott" <rell...@procard.com> wrote in message
news:%23Jmt3$nxDHA...@tk2msftngp13.phx.gbl...

Pacbell

unread,
Dec 21, 2003, 3:46:06 PM12/21/03
to
"Don Grover" <spam...@assoft.com.au> wrote in message
news:epNzmgox...@tk2msftngp13.phx.gbl...

Be sure to set sendusing to 1 when on the mail server itself. Here is
another way of doing it

'//Mail subroutine need to pass in varibles

sRecipients = "mi...@foo.com"

sFrom = "bi...@foo.com"

sSender = "j...@foo.com"

sSL = "Hellloo"

sBody = "Something"

sendalert

Sub SendAlert()

Dim iMsg

Dim iConf

Dim Flds

Const cdoSendUsingMethod =
"http://schemas.microsoft.com/cdo/configuration/sendusing"

Const cdoSendUsingPort = 2 '// Needs to be a 1 if on the local SMTP server

Const cdoSMTPServer =
"http://schemas.microsoft.com/cdo/configuration/smtpserver"

Const cdoSMTPServerPort =
"http://schemas.microsoft.com/cdo/configuration/smtpserverport"

Const cdoSMTPAuthenticate =
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"

Set iMsg = CreateObject("CDO.Message")

Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

With Flds

'// assume constants are defined within script file

.Item(cdoSendUsingMethod) = cdoSendUsingPort

.Item(cdoSMTPServer) = "192.168.2.5" '//Mail server goes here

' .Item(cdoSMTPServerPort) = 25

' .Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout

.Item(cdoSMTPAuthenticate) = cdoAnonymous

' .Item(cdoSendUserName) = "username"

' .Item(cdoSendPassword) = "password"

' .Item(cdoURLProxyServer) = "server:80"

' .Item(cdoURLProxyBypass) = "<local>"

' .Item(cdoURLGetLatestVersion) = True

.Update

End With

With iMsg

Set .Configuration = iConf

.To = sRecipients

.From = sFrom

.Sender = sSender

.Subject = sSL

.TextBody = sBody

If sAttachment <> "" Then

.AddAttachment sAttachment

End If

.Send

End With

Set iMsg = Nothing

Set iConf = Nothing

End Sub

Michael Holzemer


0 new messages