R
RD
In the following code, wen I get to SmtpMail.Send(myMessage) I get an
exception cast is invalid. I single step through the code and everuthing is
Ok till I execute that line.
Can anyone tell me whats wrong? I'm testing this on a Win XP Pro SP2. I get
the same error whether I specify a remote mail server like
"mail.myserver.mydomain.com" or if I specify local. On the local machine I
have IIS installed as well as Outlook 2003 and my mails with other progs all
work fine.
Here's the code snippet,
Thanks for any help,
Bob
Public Sub SendMailMultipleAttachments(ByVal From As String, _
ByVal sendTo As String, ByVal Subject As String, _
ByVal Body As String, _
Optional ByVal AttachmentFiles As ArrayList = Nothing, _
Optional ByVal CC As String = "", _
Optional ByVal BCC As String = "", _
Optional ByVal SMTPServer As String = "", _
Optional ByVal bTraceProgramExec As Boolean = False)
Dim myMessage As System.Web.Mail.MailMessage
Dim i, iCnt As Integer
Try
If bTraceProgramExec Then MyTrace("SendMailMultipleAttachments
start " & Now())
myMessage = New MailMessage
With myMessage
.To = sendTo
.From = From
.Subject = Subject
.Body = Body
.BodyFormat = MailFormat.Text
'CAN USER MAILFORMAT.HTML if you prefer
If CC <> "" Then .Cc = CC
If BCC <> "" Then .Bcc = ""
If Not AttachmentFiles Is Nothing Then
iCnt = AttachmentFiles.Count - 1
For i = 0 To iCnt
If FileExists(AttachmentFiles(i)) Then _
.Attachments.Add(AttachmentFiles(i))
Next
End If
End With
If SMTPServer <> "" Then
SmtpMail.SmtpServer = SMTPServer
Else
SmtpMail.SmtpServer = "local"
End If
SmtpMail.Send(myMessage)
If bTraceProgramExec Then MyTrace("SendMailMultipleAttachments
start " & Now())
Catch ex As Exception
If bTraceProgramExec Then MyTrace("SendMailMultipleAttachments
Error:" & ex.Message & " Stack Trace : " & ex.StackTrace)
End Try
End Sub
exception cast is invalid. I single step through the code and everuthing is
Ok till I execute that line.
Can anyone tell me whats wrong? I'm testing this on a Win XP Pro SP2. I get
the same error whether I specify a remote mail server like
"mail.myserver.mydomain.com" or if I specify local. On the local machine I
have IIS installed as well as Outlook 2003 and my mails with other progs all
work fine.
Here's the code snippet,
Thanks for any help,
Bob
Public Sub SendMailMultipleAttachments(ByVal From As String, _
ByVal sendTo As String, ByVal Subject As String, _
ByVal Body As String, _
Optional ByVal AttachmentFiles As ArrayList = Nothing, _
Optional ByVal CC As String = "", _
Optional ByVal BCC As String = "", _
Optional ByVal SMTPServer As String = "", _
Optional ByVal bTraceProgramExec As Boolean = False)
Dim myMessage As System.Web.Mail.MailMessage
Dim i, iCnt As Integer
Try
If bTraceProgramExec Then MyTrace("SendMailMultipleAttachments
start " & Now())
myMessage = New MailMessage
With myMessage
.To = sendTo
.From = From
.Subject = Subject
.Body = Body
.BodyFormat = MailFormat.Text
'CAN USER MAILFORMAT.HTML if you prefer
If CC <> "" Then .Cc = CC
If BCC <> "" Then .Bcc = ""
If Not AttachmentFiles Is Nothing Then
iCnt = AttachmentFiles.Count - 1
For i = 0 To iCnt
If FileExists(AttachmentFiles(i)) Then _
.Attachments.Add(AttachmentFiles(i))
Next
End If
End With
If SMTPServer <> "" Then
SmtpMail.SmtpServer = SMTPServer
Else
SmtpMail.SmtpServer = "local"
End If
SmtpMail.Send(myMessage)
If bTraceProgramExec Then MyTrace("SendMailMultipleAttachments
start " & Now())
Catch ex As Exception
If bTraceProgramExec Then MyTrace("SendMailMultipleAttachments
Error:" & ex.Message & " Stack Trace : " & ex.StackTrace)
End Try
End Sub