send mail in asp.net(C#)2008

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pskvenkat
    New Member
    • Mar 2008
    • 10

    send mail in asp.net(C#)2008

    Hello,
    This is venkat,
    I was trying to send the email using the following codes but error occurs everytime can you fix this.
    Code:
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Net.Mail;
    
        MailMessage mail = new MailMessage();
            mail.To = ToTextBox.Text;
            mail.From=FromTextBox.Text;
            mail.CC=CcTextBox.Text;
            mail.Subject=SubTextBox.Text;
            mail.Body=MsgTextBox.Text;
            System.Net.Mail.SmtpClient SmtpServer = "localhost";
            SmtpServer.Send(mail);
    is this correct format? pls send if any correct coding for that? also what are the things should declare in the top?
    Last edited by Plater; Apr 3 '08, 12:48 PM. Reason: code tags are your friend
  • GayathriP
    New Member
    • Oct 2007
    • 17

    #2
    The Port No is not specified to send the email.
    It can be done by

    SmtpServer.Port = <PortNo>;

    Comment

    • Shashi Sadasivan
      Recognized Expert Top Contributor
      • Aug 2007
      • 1435

      #3
      System.Net.Mail .SmtpClient SmtpServer = "localhost" ;

      since you are creating a SmtpClient object you have to create a new one

      i.e.
      System.Net.Mail .SmtpClient SmtpServer = new System.Net.Mail .SmtpClient("19 2.168.0.1");
      its better to send an ip address to it.
      i havent tested it using localhost. (im not sure of that), and yes you may also have to specify the port if it is not on the default smtp port which i thing is 25

      Comment

      • pskvenkat
        New Member
        • Mar 2008
        • 10

        #4
        Originally posted by Shashi Sadasivan
        System.Net.Mail .SmtpClient SmtpServer = "localhost" ;

        since you are creating a SmtpClient object you have to create a new one

        i.e.
        System.Net.Mail .SmtpClient SmtpServer = new System.Net.Mail .SmtpClient("19 2.168.0.1");
        its better to send an ip address to it.
        i havent tested it using localhost. (im not sure of that), and yes you may also have to specify the port if it is not on the default smtp port which i thing is 25

        Can you tel how can i find the smtp server port number?

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Originally posted by pskvenkat
          Can you tel how can i find the smtp server port number?
          It probably is 25. The real problem was your incorrect "constructo r" calling of the SmtpClient class

          Comment

          Working...