smtp server issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayush patel
    New Member
    • Jul 2008
    • 63

    smtp server issue

    Hi Everybody,

    i have a problem with smtp server. i developed an application on my local machine and it runs fine.it uses our smtp server to send emails. but when i uploaded the app on to the server it does not send any emails although it is using the same smtp server.

    our smtp server settings are definitly not an issue. anonymous access is given there is no limit on number of messages everything is fine.i dont know how is it able to work on local mahcine and not on server(even though both are using same smtp server)

    did anyone face this kind of problem. please let me know if you have any ideas

    Ayush
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Have you put in code to see why it is failing?

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Make sure there are no Firewalls or Proxies that could be blocking emails.

      Check your Windows event logs for any details about what might be failing...

      In your code, put try catches in and check if emails were sent success fully...if not then record it into a log so that you can determine what the problem is.

      -Frinny

      Comment

      • ayush patel
        New Member
        • Jul 2008
        • 63

        #4
        Hi all,
        thank you for replying.This code worked before. it sent emails but now it suddenly stopped working. there are no major changes we did to server settings. there are no firewalls and proxies. I cannot see anything in smtp log there are no details listed about the mail sent at that time. i tried sending emails from command prompt of that server and the emails went out.so i think this is not a server issue. but the code worked before i dont know whats wrong now. any ideas?

        Code:(text)
        [code=vbnet]
        Try
        oEmail.To = recipient
        oEmail.Subject = subject
        oEmail.Body = message
        oEmail.BodyForm at = bodyFormat
        oEmail.From = sender

        oEmail.Fields.I tem("http://schemas.microso ft.com/cdo/configuration/sendusing") = 2
        oEmail.Fields.I tem("http://schemas.microso ft.com/cdo/configuration/smtpserver") = hostSmtpServer
        oEmail.Fields.I tem("http://schemas.microso ft.com/cdo/configuration/smtpserverport" ) = 25
        oEmail.Fields.I tem("http://schemas.microso ft.com/cdo/configuration/sendusername") = "fgtt\ggggg "
        oEmail.Fields.I tem("http://schemas.microso ft.com/cdo/configuration/sendpassword") = "hghg"

        SmtpMail.SmtpSe rver = hostSmtpServer
        SmtpMail.Send(o Email)

        Catch
        End Try[/code]
        Last edited by Frinavale; Sep 22 '08, 03:24 PM. Reason: Added [code] tags

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Record any exceptions you've encountered in your Catch block....you could write it to a text file, record it to an event log....but right now you are catching the exception and not doing anything with it.

          You could remove the Try Catch block for testing purposes...when an exception is thrown it should appear in your Windows Application Event Log in this case....

          Comment

          • ayush patel
            New Member
            • Jul 2008
            • 63

            #6
            i tried catching an exception but there is no exception thrown nor i can see some error in event viewer.

            what is strange is i can send the emails from a command prompt from the server that my application is, using smtp server that is sending emails. but when i do the same thing from website it does not happen. so theres definitly something wrong with the code.

            Code:
            Public Shared Sub SendEmail(ByVal recipient As String, _
                                            ByVal sender As String, _
                                            ByVal subject As String, _
                                            ByVal message As String, _
                                            ByVal hostSmtpServer As String, _
                                            Optional ByVal bodyFormat As MailFormat = MailFormat.Html)
            
                    Dim oEmail As New MailMessage
            
                    Try
                        oEmail.To = recipient
                        oEmail.Subject = subject
                        oEmail.Body = message
                        oEmail.BodyFormat = bodyFormat
                        oEmail.From = sender
            
                        oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
                        oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = hostSmtpServer
                        oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
                        
                        SmtpMail.SmtpServer = hostSmtpServer
                        SmtpMail.Send(oEmail)
            
                    Catch Ex As Exception
                        Dim objStreamWriter As StreamWriter
                        objStreamWriter = File.AppendText("C:\sample.txt")
                        objStreamWriter.WriteLine(Ex)
                        objStreamWriter.Close()
            
                    End Try
            
                End Sub
            (Hi Frinavale,
            please let me know how to add code tags i have no idea how to do that.)


            Ayush
            Last edited by Curtis Rutland; Sep 23 '08, 01:34 PM. Reason: Added Code Tags - Please use the # button

            Comment

            • Curtis Rutland
              Recognized Expert Specialist
              • Apr 2008
              • 3264

              #7
              You can use the # button on the text editor to insert your opening and closing code tags.

              It's like HTML with square brackets instead. [CODE] to open, and you close by putting a slash in between the bracket and the c: [/C

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                What version of .NET are you using and what namesapce are you using to create your MailMessage?

                The only thing that I'm unsure of in your code is the use of the Fields property. Looking up the MailMessage control (in the System.Net.Mail namespace) I don't see a Fields property at all...I've never used this property.

                Anyways, give the following code a try and see if it works.
                (Please note that right now I'm unable to fully test the code so it may not work 100%)

                Code:
                 Public Shared sub SendEmail(ByVal recipient As String, _
                   ByVal sender As String, _
                   ByVal subject As String, _
                   ByVal message As String, _
                   ByVal hostSmtpServer As String, _
                   Optional ByVal bodyFormat As MailFormat = MailFormat.Html)
                  
                
                  
                  Try
                  'oEmail.To = recipient
                  'oEmail.Subject = subject
                  'oEmail.Body = message
                  'oEmail.BodyFormat = bodyFormat
                  'oEmail.From = sender
                 
                 'oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
                 'oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = hostSmtpServer
                 'oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
                oEmail= New Net.Mail.MailMessage(sender, recipient, subject, message)
                
                
                'SmtpMail.SmtpServer = hostSmtpServer
                'SmtpMail.Send(oEmail)
                
                Dim mailClient As New Net.Mail.SmtpClient(hostSmtpServer, 25)
                mailClient.Send(oEmail)
                  
                 Catch Ex As Exception
                 Dim objStreamWriter As StreamWriter
                 objStreamWriter = File.AppendText("C:\sample.txt")
                 objStreamWriter.WriteLine(Ex)
                 objStreamWriter.Close()
                
                 End Try
                
                 End Sub
                Also, does your mail server provider require credentials in order to send emails?

                -Frinny

                Comment

                • ayush patel
                  New Member
                  • Jul 2008
                  • 63

                  #9
                  Hi,

                  I am using .NET 1.1 VS 2003. I am using "Imports System.Web.Mail " mail sever does not need credentials . I removed credentials and checked it it still doesn't send any emails.

                  Comment

                  Working...