Invalid Cast Ex in SendMail
Hi Everyone
I'm having a bit of trouble getting a routine to work and I can't quite figure out whats wrong. It keeps throwing an 'invalid cast exception'. :mad: Any ideas? Thanks,
Cdog
VB Code:
Sub SendMailProcessing()
Dim myMessage As New MailMessage
Dim str As New StringBuilder
Dim StylePath As String = Session("MyStylePath") 'path to an uploaded pic
Dim PicturePath As String = Session("MyPicturePath")'path to an uploaded pic
MyList = Session("List")
'build the body of the email
str.Append("First Name: " & MyList("First_Name") & ControlChars.CrLf)
str.Append("Last Name: " & MyList("Last_Name") & ControlChars.CrLf)
str.Append("Address: " & MyList("Address") & ControlChars.CrLf)
str.Append("Apartment Number: " & MyList("Apt") & ControlChars.CrLf)
str.Append("City: " & MyList("City") & ControlChars.CrLf)
str.Append("State: " & MyList("State") & ControlChars.CrLf)
str.Append("Zip: " & MyList("Zip") & ControlChars.CrLf)
str.Append("Phone: " & MyList("Phone") & ControlChars.CrLf)
str.Append("Email: " & MyList("Email") & ControlChars.CrLf & ControlChars.CrLf)
str.Append("BaseColor: " & MyList("Base_Color") & ControlChars.CrLf)
str.Append("Hair Type: " & MyList("Hair_Type") & ControlChars.CrLf)
str.Append("Wave Type: " & MyList("Wave_Type") & ControlChars.CrLf)
str.Append("Front to back measurement: " & MyList("Front_to_Back_Measurement") & ControlChars.CrLf)
str.Append("Side to side measurement: " & MyList("Side_to_Side_Measurement") & ControlChars.CrLf)
str.Append("Top Length: " & MyList("Top_Length") & ControlChars.CrLf)
str.Append("Front_Length: " & MyList("Front_Length") & ControlChars.CrLf)
str.Append("Side Length: " & MyList("Side_Length") & ControlChars.CrLf)
str.Append("Back Length: " & MyList("Back_Length") & ControlChars.CrLf & ControlChars.CrLf)
str.Append("Special Instructions: " & MyList("Special_Instructions") & ControlChars.CrLf)
With myMessage
.From = MyList("Email")
.Subject = "Incoming Order"
.Body = str.ToString
.BodyFormat = MailFormat.Text
If StylePath <> "" Then
.Attachments.Add(StylePath)
End If
If PicturePath <> "" Then
.Attachments.Add(PicturePath)
End If
End With
SmtpMail.Send(myMessage)
End Sub
Re: Invalid Cast Ex in SendMail
Which line throws the exception?
Re: Invalid Cast Ex in SendMail
Wild Bill
Here's what shows up:
VB Code:
Source Error:
Line 149: End With
Line 150:
[COLOR=DarkRed]Line 151: SmtpMail.Send(myMessage)[/COLOR]
Line 152: lblMessage.Text = "Mail has been sent"
Line 153: End Sub
Source File: ####.aspx Line: 151
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
System.Web.Mail.CdoSysHelper.Send(MailMessage message) +769
System.Web.Mail.SmtpMail.Send(MailMessage message) +153
Thanks!
Cdog :confused:
Re: Invalid Cast Ex in SendMail
After 3 beers and 2 pots of coffee -->
Oops....
VB Code:
strFolder = "temps/" 'my original goofy line in my upload sub
strFolder = Server.MapPath("temps/") 'changed it to this
And added these to the SendMail:
VB Code:
Dim oAttch1 As MailAttachment = New MailAttachment(StylePath)
Dim oAttch2 As MailAttachment = New MailAttachment(PicturePath)
And it seems to be happy :rolleyes: goodnight
Cdog