web app - need to send email from the application

Hi,

     In my webapp, I need to be able to send an error report to myself when the user clicks the button.  Basically some session variables hold the last information entered in text boxes when the Save button is pressed, so that if they see they made an error then they can just click the "Send Error Report" button and the program will email me the exact transaction they made so I can fix it.  Here's my code for the email, but it's not working:

    Private Sub cmdRepErr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRepErr.Click
        Dim Msg As String
        Msg = "Description: " + Session("L_Desc") + "<BR>Stock on Hand: " + Session("L_SOH") + _
            "<BR>Reorder Qty: " + Session("L_reQty") + "<BR>Issued To: " + Session("L_Cust") + _
            "<BR>Issue Date: " + Session("L_Date") + "<BR>Quantity: " + Session("L_Qty") + _
            "<BR>Units: " + Session("L_Units")

        Dim myMessage As New MailMessage
        Dim myMailServer As SmtpMail
        myMessage.BodyFormat = MailFormat.Text
        myMessage.Priority = MailPriority.Normal
        myMessage.From = "OEL2"
        myMessage.To = "myemail@me.com"   ' replaced this for privacy
        myMessage.Subject = "OEL2 Error Reported"
        myMessage.Body = Msg
        myMailServer.Send(myMessage)
        myMessage = Nothing
    End Sub

When I run it, I get this:

The "SendUsing" configuration value is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The "SendUsing" configuration value is invalid.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[COMException (0x80040220): The "SendUsing" configuration value is invalid.
]

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
   System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
   System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +58

[HttpException (0x80004005): Could not access 'CDO.Message' object.]
   System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +111
   System.Web.Mail.CdoSysHelper.Send(MailMessage message) +1861
   System.Web.Mail.SmtpMail.Send(MailMessage message) +150
   OEL2.Supplies.cmdRepErr_Click(Object sender, EventArgs e) in \\ga1cdc02\c$\Inetpub\wwwroot\OEL2\Supplies.aspx.vb:621
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1292

 
Thanks!

JP
gleznovAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gleznovAuthor Commented:
Actually, I kinda understand the problem, but I don't know what to set as the sendusing.  I had it as was for a windows app which I think used my outlook express to send the emails.  How do I determine this?  Is it our domain?

JP
0
GlomCommented:
Hi, try :

        Dim myMessage As New MailMessage

        myMessage.BodyFormat = MailFormat.Text
        myMessage.Priority = MailPriority.Normal
        myMessage.From = "OEL2"
        myMessage.To = "myemail@me.com"   ' replaced this for privacy
        myMessage.Subject = "OEL2 Error Reported"
        myMessage.Body = Msg

        SmtpMail.SmtpServer = "..." ' The name of your smtp server
        SmtpMail.Send(myMessage)

        myMessage = Nothing

As SmtpMail has only shared function, you don't need to declare it to access its methods. I think the problem came from the SMTP server that wasn't set.

Glom
0
gleznovAuthor Commented:
How do I find out what my smtp server is?

JP
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

GlomCommented:
Hmm, ask your network admin, or if you can't know it, enter "localhost". If you are running on Windows XP, this may work...
0
gleznovAuthor Commented:
OK I got it, but I got this:

The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for myemail@me.com  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for myemail@me.com

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below


For this error message, I just changed my email to myemail@me.com - that's not actually what's in the code/error msg.

JP
0
GlomCommented:
OK

If you have entered localhost as smtp server, try to put the one you can find in your outlook (express) config. This must be a valid smtp server connected to the internet. He must know how to access the domain me.com (in your example).
0
gleznovAuthor Commented:
This is server-side right?  Where is the outlook config file?  I don't see one in program files/outlook express

JP
0
gleznovAuthor Commented:
OK our admin is telling me the server's Outlook isn't set up and can't be - it's not on a normal network and would have to be set up for a particular user if at all.  Is there some other way I can send email?  Maybe java or something that doesn't try to use a pre-existing program such as Outlook?

JP
0
GlomCommented:
In fact, the .NET SmtpMail is not related to outlook, I simply suggested to look inside your outlook config to find a valid SMTP Server. But if your outlook is not set up, you can't. We'll find another then, a public qmtp server for example.

I'm absolutely not sure of it, but try to enter "smtp.google.com", this could work, miracles happen ;)
0
tusharashahCommented:
550 is a well know SMTP Error Message which means Unable to relay for xy. To be short the SMTP has verified that you are not allowed to send a mail with the current user.

Add following line and see if it helps with the error:
>>> msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",2);

-tushar
0
tusharashahCommented:
IF that do not work, then you can always pass a Valid UserName and Password of the User who is allowed to use your SMTP server.. (may be yours! if you can send/receive email)

Following is the Example of how you can do that:

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 2)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "YourExchangeUserName")
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "YourExchangePassword")
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "YourServerName" )
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 10)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", false)

-tushar
0
gleznovAuthor Commented:
Getting closer...  Is there code I can use to pass authentication username/password?  That's what my admin tells me I'll need to do to use the server to send an email.

JP
0
tusharashahCommented:
Your Complete program should be like following then:

------------------------------------------------------------------------------------------------------------------------------------------------------------
    Private Sub cmdRepErr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRepErr.Click
        Dim Msg As String
        Msg = "Description: " + Session("L_Desc") + "<BR>Stock on Hand: " + Session("L_SOH") + _
            "<BR>Reorder Qty: " + Session("L_reQty") + "<BR>Issued To: " + Session("L_Cust") + _
            "<BR>Issue Date: " + Session("L_Date") + "<BR>Quantity: " + Session("L_Qty") + _
            "<BR>Units: " + Session("L_Units")

        Dim myMessage As New MailMessage
        Dim myMailServer As SmtpMail
        myMessage.BodyFormat = MailFormat.Text
        myMessage.Priority = MailPriority.Normal
        myMessage.From = "OEL2"
        myMessage.To = "myemail@me.com"   ' replaced this for privacy
        myMessage.Subject = "OEL2 Error Reported"
        myMessage.Body = Msg

      myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 2)
      myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "YourExchangeUserName")
      myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "YourExchangePassword")
      myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2)
      myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "YourServerName" )
      myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 10)
      myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25)
      myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", false)

        myMailServer.Send(myMessage)
        myMessage = Nothing
    End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------
0
gleznovAuthor Commented:
I got:

The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available

My code is exactly as shown above (with email changed).

JP
0
gleznovAuthor Commented:
Oh, and of course I plugged in the username/pass/server

JP
0
tusharashahCommented:
Try to replace this line
myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 2)

with

myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)

-tushar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tusharashahCommented:
Just found out that if UserName and Password are incorrect then you'll see following error msg:

'The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available.'

Double check your password and that account has permission to send email.

This line should be fine at it's place:
 myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 2)


-tushar
0
gleznovAuthor Commented:
WOOHOO!  Once again Tush, you're da man.

JP
0
tusharashahCommented:
Nice to have you going JP :)

-tushar
0
tusharashahCommented:
Also, can you post the Exact Code that worked for you.. for future reference..

-tushar
0
gleznovAuthor Commented:
No.  Mine.
0
gleznovAuthor Commented:
Just playing ;)  


Dim myMessage As New MailMessage
        Dim myMailServer As SmtpMail
        myMessage.BodyFormat = MailFormat.Text
        myMessage.Priority = MailPriority.Normal
        myMessage.From = "OEL2"
        myMessage.To = "john.owens@dyncorp.com"
        myMessage.Subject = "OEL2 Error Reported"
        myMessage.Body = Msg
        'SmtpMail.SmtpServer = "tx1xch03.tx.dynhq.ad"
        'SmtpMail.Send(myMessage)

        myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)
        myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "tx\owensjo")
        myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "dyn0weN*")
        myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2)
        myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "tx1xch03.tx.dynhq.ad")
        myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 10)
        myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25)
        myMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", False)

        myMailServer.Send(myMessage)
        myMessage = Nothing
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.