Problem sending email via .NET code on new server

riley

Perch
While testing my sites that were just moved to the new server, I got an error sending email from .NET code.

The error logged by my code's try/catch block is as follows:
"Could+not+access+'CDO.Message'+object"

Here is the code I use:

Public Function SendEmail(ByVal FromEmail As String, ByVal ToEmail As String, ByVal Subject As String, ByVal Message As String) As Boolean
Dim ReturnValue As Boolean = False
Dim objMail As System.Web.Mail.SmtpMail
Dim objMsg As System.Web.Mail.MailMessage

objMsg = New Web.Mail.MailMessage()
objMsg.From = FromEmail
objMsg.To = ToEmail
objMsg.Subject = "(WebEmail): " & Subject
objMsg.Body = Message
objMsg.BodyFormat = MailFormat.Html
Try
objMail.Send(objMsg)
ReturnValue = True
Catch ex As Exception
mResponse.AppendToLog("Email error:" & ex.Message)
ReturnValue = False
End Try
Return ReturnValue
End Function

This worked on the old server. Any help on this would be appreciated.
Thanks,
riley
 
We just gave full ASP.NET permissions to the mailroot folder. Tell me if that solved the problem. If not, please give us the full error message (or point us to the URL)
 
I had a similar problem and I fixed it last night. If you display the entire exception by using something like this - mResponse.AppendToLog("Email error:" & ex.ToString()) you will see a lot more info.

When I did this I saw the full error and it actually included a URL in the error telling me where to find more info.

The error I was getting had to do with line feed (LF) characters in the message. Apparently the QMAIL software on the new web server is picky about having LF without a matching CR. It wants to see CR+LF not just LF. I've seen this problem before with PHP apps.

Anyway, my fix was to convert all LF characters to CR+LF in the message body. In your code it would be something like this:

objMsg.Body = Message.Replace("\n", "\r\n");

(this is the C# syntax - not sure how to indicate CR and LF in VB)

Hope this helps.



riley said:
While testing my sites that were just moved to the new server, I got an error sending email from .NET code.

The error logged by my code's try/catch block is as follows:
"Could+not+access+'CDO.Message'+object"

This worked on the old server. Any help on this would be appreciated.
Thanks,
riley
 
Yash said:
We just gave full ASP.NET permissions to the mailroot folder. Tell me if that solved the problem. If not, please give us the full error message (or point us to the URL)

Still doesn't work.
As for the error message, there is nothing more to it. The error is handled in my code and the .Net exception message is written to the IIS log. The .Net exception message is what I posted before.

Because the error is handled in the code, you will not see an IIS generated error page. I compile the application before uploading it and upload only the DLLs and aspx pages, so there is no .NET source code you could look at in my site's folders. But here is the url, in case you want to try some other things and test the results:
http://www.chicagomagic8990g.com/webemail.aspx

Thanks,
riley
 
riley said:
Interesting...

brawney, what exception message were you seeing?

riley

The ex.Message message was a generic CDO object error. Once I started catching the fill exception I found the mention of LF problems. Sorry, but I don't remember the specific message. QMail was obviously generating the message and it was nice enough to give me a URL to read more about the error.

I had other places in my site using the same code to send mail and they were working so I didn't think it was a server or mail server problem. I found that the text being sent from this one location didn't have CR+LF in it, just LF.
 
Yash said:
Looks like CDO is not installed on Win2003 by default. We're looking into this

Yash, assuming Riley is on win1 with me his stuff should be working. Mine works fine. There was a thread a few weeks back about CDONTS not being installed with Win 2003. Someone said you can go ahead and load it anyway. You did load it and it's been working fine.
 
brawney said:
Yash, assuming Riley is on win1 with me his stuff should be working. Mine works fine. There was a thread a few weeks back about CDONTS not being installed with Win 2003. Someone said you can go ahead and load it anyway. You did load it and it's been working fine.

I just looked around the web and found this is a very common problem -- lots of posts out there about it. Unfortunately, there are many reasons sited for the problem and many different solutions posted on the web, each of which is claimed to have fixed it. Obviously, more information is needed for this specific case.

The .NET exception message generated in this case is very generic, as brawney mentioned. So when I get a chance, I will modify the code to reveal more detailed exception information and see what I can find out.

Unfortunately, it's Christmas eve and this Santa has lots of wrapping to do. I hope I can get to this a little later today. One must keep one's priorities in line you know...
 
Yash said:
We just gave full ASP.NET permissions to the mailroot folder. Tell me if that solved the problem. If not, please give us the full error message (or point us to the URL)

Listed below is the entire exception. Most of it is a stack trace, which I included in case you need it. The most significant piece of information is the System.Runtime.InteropServices.COMException that states, "The+"SendUsing"+configuration+value+is+invalid."

System.Web.HttpException:+Could+not+access+'CDO.Message'+object.+--->+System.Reflection.TargetInvocationException:+Exception+has+been+thrown+by+the+target+of+an+invocation.+--->+System.Runtime.InteropServices.COMException+(0x80040220):+The+"SendUsing"+configuration+value+is+invalid.+++++++---+End+of+inner+exception+stack+trace+---+++++at+System.RuntimeType.InvokeDispMethod(String+name,+BindingFlags+invokeAttr,+Object+target,+Object[]+args,+Boolean[]+byrefModifiers,+Int32+culture,+String[]+namedParameters)+++++at+System.RuntimeType.InvokeMember(String+name,+BindingFlags+invokeAttr,+Binder+binder,+Object+target,+Object[]+args,+ParameterModifier[]+modifiers,+CultureInfo+culture,+String[]+namedParameters)+++++at+System.Web.Mail.LateBoundAccessHelper.CallMethod(Object+obj,+String+methodName,+Object[]+args)+++++---+End+of+inner+exception+stack+trace+---+++++at+System.Web.Mail.LateBoundAccessHelper.CallMethod(Object+obj,+String+methodName,+Object[]+args)+++++at+System.Web.Mail.CdoSysHelper.Send(MailMessage+message)+++++at+System.Web.Mail.SmtpMail.Send(MailMessage+message)+++++at+snappconsulting.scd.SendEmail(String+FromEmail,+String+ToEmail,+String+Subject,+String+Message)



Hope this helps.
riley
 
riley said:
System.Runtime.InteropServices.COMException that states, "The+"SendUsing"+configuration+value+is+invalid."

After some more reading and experimentation, I tried setting the SmtpServer property, which I didn't have to do on the old server, and it seems to have worked. (objMail.SmtpServer = "mail.mydomain.com") Well, the error no longer occurs and I can see the message using webmail (the problem page is a way for visitors to email me). I can't seem to pick it up with my pop3 client, but I think some of my ISP's DNS servers are still resolving to the old jodohost servers. We shall see, but I think this has solved the problem.

riley
 
brawney said:
If you were using "local" as the SMTP server name before you need to change that to mail.yourdomain.com

I was not setting the property on the old server, but I think "local" is the default value. I think it's working ok now that I'm setting it to mail.mydomain.com.

riley
 
riley said:
I was not setting the property on the old server, but I think "local" is the default value. I think it's working ok now that I'm setting it to mail.mydomain.com.

riley

Cool. I forgot about that setting. Part of my site was working fine but another part wasn't. That other part wasn't using CR+LF, only LF, and causing qmail to raise an error. But when I first moved to win1 I had to change the SMTP server name.
 
Back
Top