?
Solved

web app - need to send email from the application

Posted on 2004-11-09
22
Medium Priority
?
387 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:gleznov
  • 11
  • 7
  • 4
22 Comments
 

Author Comment

by:gleznov
ID: 12533200
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
 
LVL 4

Expert Comment

by:Glom
ID: 12533453
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
 

Author Comment

by:gleznov
ID: 12533512
How do I find out what my smtp server is?

JP
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:Glom
ID: 12533771
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
 

Author Comment

by:gleznov
ID: 12533909
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
 
LVL 4

Expert Comment

by:Glom
ID: 12534214
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
 

Author Comment

by:gleznov
ID: 12534461
This is server-side right?  Where is the outlook config file?  I don't see one in program files/outlook express

JP
0
 

Author Comment

by:gleznov
ID: 12534562
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
 
LVL 4

Assisted Solution

by:Glom
Glom earned 1000 total points
ID: 12534874
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12534945
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12535035
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
 

Author Comment

by:gleznov
ID: 12535047
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12535098
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
 

Author Comment

by:gleznov
ID: 12535379
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
 

Author Comment

by:gleznov
ID: 12535382
Oh, and of course I plugged in the username/pass/server

JP
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 1000 total points
ID: 12536080
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12536173
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
 

Author Comment

by:gleznov
ID: 12536190
WOOHOO!  Once again Tush, you're da man.

JP
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12536234
Nice to have you going JP :)

-tushar
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12536244
Also, can you post the Exact Code that worked for you.. for future reference..

-tushar
0
 

Author Comment

by:gleznov
ID: 12536498
No.  Mine.
0
 

Author Comment

by:gleznov
ID: 12536502
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question