send mails

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muskan
    New Member
    • Nov 2006
    • 35

    send mails

    Hello,

    I have written this code for sending mails but is not working.
    Tell what should I have to write after the equal sign in
    SmtpMail.SmtpSe rver = ;

    so mail to be stored in /Inetpub/mailroot/queue & also how can I send External mails throu this code.


    MailMessage msgmail= new MailMessage();
    msgmail.From = txtFrom.Text;
    msgmail.To = txtTo.Text;
    msgmail.Subject = txtSubject.Text ;
    msgmail.Body =txtMessage.Tex t;
    //SmtpMail.SmtpSe rver = "IP Address"
    SmtpMail.SmtpSe rver =;
    //send message
    SmtpMail.Send(m sgmail);
    //clear TO,Subject,mess age fields
    txtTo.Text="";
    txtSubject.Text ="";
    txtMessage.Text ="";
    //show status
    litStatus.Text ="<p>Message sent.</p>";

    Pls reply ASAP...........
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    That would be the name of your smtp server, which you will need to find out from host server provider - smtp.domain.com format. If they don't provide this service, you may be out of luck but check with your ISP.

    Hope that this helps.

    Comment

    • karthi84
      Contributor
      • Dec 2006
      • 270

      #3
      if u have a gmail account then u can use "smtp.gmail.com " i have not tried with other servers. but here it requires your authentication for sending mails. so add the authentication codes also to it.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Make sure that your email server is on port 25...if this isn't the case, then you'll have to specify the port.

        If your email server requires a user name and password in order to use it, look up System.Net.Netw orkCredential

        I'm not sure, but is the email server on the same machine as the webserver?
        Is are both of these on the computer that you are currently developing on? If this is the case you'll need to use "localhost" as your SMTPServer.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by karthi84
          if u have a gmail account then u can use "smtp.gmail.com " i
          have not tried with other servers. but here it requires your authentication for sending mails. so add the authentication codes also to it.
          Just tried this in my own code. I kept getting an exception stating that my connection was actively refused by the server. Are you sure this works?

          -F

          Comment

          • karthi84
            Contributor
            • Dec 2006
            • 270

            #6
            Originally posted by Frinavale
            Just tried this in my own code. I kept getting an exception stating that my connection was actively refused by the server. Are you sure this works?

            -F
            i tried this in my codes and now i am able to send messages. you post the codes and i will find the problem in it for you

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by karthi84
              i tried this in my codes and now i am able to send messages. you post the codes and i will find the problem in it for you
              I've been encountering a few emailing problems of my own lately and thought by trying gmail it could clarify some of my concerns. I think my problem is issues with a WinSock Proxy Server in place....but if you see anything wrong with my coded I would be happy to hear about it.

              Code:
                Dim emailMessage As Net.Mail.MailMessage
                Dim body As String = compileEmailMessage()
                Dim emailTitle As String = "Testing Email"
                
                emailMessage = New Net.Mail.MailMessage("username@gmail.com", "username@gmail.com", emailTitle, body)
              
                Dim mailClient As New Net.Mail.SmtpClient("smtp.gmail.com")
                Dim myCredentials As New System.Net.NetworkCredential("username", "password")
                mailClient.UseDefaultCredentials = False
                mailClient.Credentials = myCredentials
                mailClient.Send(emailMessage)
              Thanks a lot

              -F

              Comment

              • karthi84
                Contributor
                • Dec 2006
                • 270

                #8
                Hi Frinavale ,
                try out this code. this should help u. any doubt post a pm to me.

                Code:
                Dim mailClient As New System.Net.Mail.SmtpClient()
                Dim basicAuthenticationInfo As _
                         New System.Net.NetworkCredential("user@gmail.com", "password")mailClient.Host = "smtp.gmail.com"
                mailClient.UseDefaultCredentials = False
                mailClient.Credentials = basicAuthenticationInfo
                mailClient.EnableSsl = True
                Dim Email As New System.Net.Mail.MailMessage( _
                         "from@gmail.com", "to@anyserver.com")
                Email.Subject = "test subject"
                Email.Body = "this is a test"
                mailClient.Send(Email)
                do post a reply if u have any doubt.

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  Originally posted by karthi84
                  Hi Frinavale ,
                  try out this code. this should help u. any doubt post a pm to me.

                  Code:
                  Dim mailClient As New System.Net.Mail.SmtpClient()
                  Dim basicAuthenticationInfo As _
                           New System.Net.NetworkCredential("user@gmail.com", "password")mailClient.Host = "smtp.gmail.com"
                  mailClient.UseDefaultCredentials = False
                  mailClient.Credentials = basicAuthenticationInfo
                  mailClient.EnableSsl = True
                  Dim Email As New System.Net.Mail.MailMessage( _
                           "from@gmail.com", "to@anyserver.com")
                  Email.Subject = "test subject"
                  Email.Body = "this is a test"
                  mailClient.Send(Email)
                  do post a reply if u have any doubt.
                  Are you sure that gmail allows Any application to use its SMTP to send emails? I think that the gmail server could be abused if they did allow this.

                  Did you, maybe, sign up with a special account that allows you to use gmail's SMTP Server to send emails?

                  I was still unable to connect to gmail with the code you supplied.
                  The exception error was:
                  "No connection could be made because the target machine actively refused it"

                  My thoughts are that this is what I'm supposed to be seeing. If gmail allowed anyone to use their server to send emails from any old application their server could be abused.

                  -F

                  Comment

                  • AricC
                    Recognized Expert Top Contributor
                    • Oct 2006
                    • 1885

                    #10
                    To test whether it is possible try to use PHP, ASP, or something else to send a SMTP message through gmail.

                    Comment

                    • maxamis4
                      Recognized Expert Contributor
                      • Jan 2007
                      • 295

                      #11
                      I like this method, avoiding smtp companies will block smtp traffic to avoid getting spammed or attacked

                      Code:
                      Dim objOutlook As Object
                      Dim objOutlookMsg As Object
                      Set objOutlook = CreateObject("Outlook.Application")
                      Set objOutlookMsg = objOutlook.CreateItem(0)
                      With objOutlookMsg
                      .To = "you@email.com
                      .Cc = "ifneed@copy.com"
                      .Subject = "Hello World (one more time)..."
                      .Body = "This is the body of message"
                      .HTMLBody = "HTML version of message"
                      .Attachments.Add ("c:\myFileToSend.txt")
                      .Send 'Let´s go!
                      End With
                      Set objOutlookMsg = Nothing
                      Set objOutlook = Nothing

                      Comment

                      Working...