problem with smtp mail sending

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweatha
    New Member
    • Mar 2008
    • 44

    problem with smtp mail sending

    Hi

    I have the normal server and not the SMTP service installed. I need to send a mail once if I click a button. Can anybody help me regarding that
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi sweatha,

    You will need to do one of the following:

    Specify the name or IP address of a mail server in your code

    or

    Install the Default SMTP Server on your IIS. You can find it in the Add/Remove Programs, Add Components section of the Control Panel.

    There is an article on the code required for sending mail here which may help you and this website has some useful tips for configuring your mail object further.

    Let me know how you get on

    Dr B

    Comment

    • sweatha
      New Member
      • Mar 2008
      • 44

      #3
      Originally posted by DrBunchman
      Hi sweatha,

      You will need to do one of the following:

      Specify the name or IP address of a mail server in your code

      or

      Install the Default SMTP Server on your IIS. You can find it in the Add/Remove Programs, Add Components section of the Control Panel.

      There is an article on the code required for sending mail here which may help you and this website has some useful tips for configuring your mail object further.

      Let me know how you get on

      Dr B
      Yes I installed. Thank You...

      Comment

      • sweatha
        New Member
        • Mar 2008
        • 44

        #4
        Problem with sending Email

        Hi

        By getting the emailId from "txtTo"-TextBox and by clicking the button, I should send the email to the emailId which is in the txtTo-TextBox. For that I have given the code as

        Imports System
        Imports System.Net
        Imports System.Web.Mail
        Imports System.Net.Mail

        Partial Class Default3
        Inherits System.Web.UI.P age
        Protected Sub Button1_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button1.Click
        Try

        Dim emailTitle As String = "My Email Title"
        Dim emailMessage As Net.Mail.MailMe ssage
        Dim body As String = "This will appear in the body of my email"
        emailMessage = New Net.Mail.MailMe ssage("importan t.project@gmail .com", "txtTo", emailTitle, body)
        Dim mailClient As New Net.Mail.SmtpCl ient("urlOfEmai lService.com", 25)
        mailClient.Send (emailMessage)

        Catch ex As Exception
        End Try
        End Sub

        End Class


        If I run the project, it is not showing any error but the mail is not getting sent.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          *merged*

          Moderator

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            Well, you won't show any error if you use a Try Catch block, and don't do anything with the Exception.

            Change your code to this:
            [CODE=VBNET]
            Catch ex As Exception
            MsgBox(ex.Messa ge)
            End Try
            [/code]

            Then you will get a popup about your exception, if there is one.

            Also, make sure that the sender address you chose is whitelisted on the receiver's email. You might be successfully sending mail, but being blocked or sent to junk mail.

            Originally posted by sweatha
            Hi

            By getting the emailId from "txtTo"-TextBox and by clicking the button, I should send the email to the emailId which is in the txtTo-TextBox. For that I have given the code as

            Imports System
            Imports System.Net
            Imports System.Web.Mail
            Imports System.Net.Mail

            Partial Class Default3
            Inherits System.Web.UI.P age
            Protected Sub Button1_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button1.Click
            Try

            Dim emailTitle As String = "My Email Title"
            Dim emailMessage As Net.Mail.MailMe ssage
            Dim body As String = "This will appear in the body of my email"
            emailMessage = New Net.Mail.MailMe ssage("importan t.project@gmail .com", "txtTo", emailTitle, body)
            Dim mailClient As New Net.Mail.SmtpCl ient("urlOfEmai lService.com", 25)
            mailClient.Send (emailMessage)

            Catch ex As Exception
            End Try
            End Sub

            End Class


            If I run the project, it is not showing any error but the mail is not getting sent.

            Comment

            • sweatha
              New Member
              • Mar 2008
              • 44

              #7
              problem with smtp mail sending

              Hi

              Through smtp I have to send email by getting the "To"-Email Id from textbox named txtTo. For that I have given the coding as

              Code:
              Imports System
              Imports System.Net
              Imports System.Web.Mail
              Imports System.Net.Mail
              
              Partial Class Default3
                  Inherits System.Web.UI.Page
                  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
              
              
                  End Sub
              
                  
                  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
                      Dim msg As New Net.Mail.MailMessage("important.project@gmail.com", txtTo.Text, "Re: Hello", "Hello Friend")
                      Dim mySmtp As New Net.Mail.SmtpClient("IP ADDRESS")
                      Try
                          mySmtp.Send(msg)
                          Label1.Text = "Mail Sent"
                      Catch ex As Exception
                          Label1.Text = ex.Message
                      End Try
                  End Sub
              
              End Class
              But once I run the project it shows the error message (on Label1) as

              "Failure sending mail."
              ---------------------------------------------------
              I have already given my issue under the topic "Problem with email sending". But just now I have changed my coding in the above manner.
              Last edited by kenobewan; May 14 '08, 12:50 PM. Reason: Added code tags

              Comment

              • DrBunchman
                Recognized Expert Contributor
                • Jan 2008
                • 979

                #8
                I think you'll probably find that you have McAfee of something similar blocking your smtp from sending mail. Have you got a virus scanner or firewall running on this server?

                Dr B

                P.S. Please remember to use the code tags (the # button) to surround your code blocks as it makes your posts much easier to read. Thanks.
                Last edited by DrBunchman; May 14 '08, 11:05 AM. Reason: Added P.S.

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  sweatha, I have once again merged your threads on smtp email troubles.
                  Please DO NOT continue to double post your questions, it's against the posting guidelines.

                  MODERATOR


                  That being said, *many* smtp servers will reject/deny the sending of emails from a user until they have verified their login credentials. In your code you appear to not send user credentials so the SMTP might be rejecting it based on that.

                  Comment

                  • Curtis Rutland
                    Recognized Expert Specialist
                    • Apr 2008
                    • 3264

                    #10
                    Originally posted by sweatha
                    .....
                    Code:
                            Try
                                mySmtp.Send(msg)
                                Label1.Text = "Mail Sent"
                            Catch ex As Exception
                                Label1.Text = ex.Message
                            End Try
                        End Sub
                    
                    End Class
                    But once I run the project it shows the error message (on Label1) as

                    "Failure sending mail."
                    ...
                    OK, that exception wasn't very detailed.

                    Adding another label (Label2) and adding this code into your Catch block:
                    Code:
                    Label2.Text = ex.InnerException.Message
                    So if there is another, more descriptive message, you can trace it.

                    Other than that, you probably have an issue external to your program blocking you.

                    Comment

                    Working...