Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to send an email ?

How to send an email ?

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasehelptutorial
17 Posts 2 Posters 18 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tina newcoder
    wrote on last edited by
    #1

    I want to send an email through my ASP.NET application. Please help me. I have the email address stored in the database . :)

    P 1 Reply Last reply
    0
    • T tina newcoder

      I want to send an email through my ASP.NET application. Please help me. I have the email address stored in the database . :)

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      Go through System.Net.Mail namespace. http://msdn.microsoft.com/de-de/library/system.net.mail.aspx[^] Or you looking something different ?

      Parwej Ahamad R & D: REST services with WCF

      T 1 Reply Last reply
      0
      • P Parwej Ahamad

        Go through System.Net.Mail namespace. http://msdn.microsoft.com/de-de/library/system.net.mail.aspx[^] Or you looking something different ?

        Parwej Ahamad R & D: REST services with WCF

        T Offline
        T Offline
        tina newcoder
        wrote on last edited by
        #3

        can i send the email through the localhost, i mean through my machine directly ? I have installed SMTP Virtual Servers in IIS 6.0, through the XP CD ! :)

        P 1 Reply Last reply
        0
        • T tina newcoder

          can i send the email through the localhost, i mean through my machine directly ? I have installed SMTP Virtual Servers in IIS 6.0, through the XP CD ! :)

          P Offline
          P Offline
          Parwej Ahamad
          wrote on last edited by
          #4

          I think no but you can verify it whether are you able to send or not. provide the SMTP server name is 172.0.0.1. Send mail through the code and check on below location you will found there some file. Open it into the notepad. C:\Inetpub\mailroot\Queue

          Parwej Ahamad R & D: REST services with WCF

          T 1 Reply Last reply
          0
          • P Parwej Ahamad

            I think no but you can verify it whether are you able to send or not. provide the SMTP server name is 172.0.0.1. Send mail through the code and check on below location you will found there some file. Open it into the notepad. C:\Inetpub\mailroot\Queue

            Parwej Ahamad R & D: REST services with WCF

            T Offline
            T Offline
            tina newcoder
            wrote on last edited by
            #5

            it is giving SmtpException Failure sending mail. what shall I do ?

            P 1 Reply Last reply
            0
            • T tina newcoder

              it is giving SmtpException Failure sending mail. what shall I do ?

              P Offline
              P Offline
              Parwej Ahamad
              wrote on last edited by
              #6

              Where you are providing the SMTP Server name in Web.config file ? IF Yes then examine like this: <system.net> <mailsettings> <smtp from="test@par.com"> <network host="172.0.0.1 OR localhost" port="25" username="" password="" defaultcredentials="true" /> </smtp> </mailsettings> </system.net> OR try external SMTP Server of Gmail

              System.Net.Mail.SmtpClient email = new System.Net.Mail.SmtpClient();
              email.Host = "smtp.gmail.com";
              email.Port = 465 ;
              ............
              ............

              Parwej Ahamad R & D: REST services with WCF

              T 1 Reply Last reply
              0
              • P Parwej Ahamad

                Where you are providing the SMTP Server name in Web.config file ? IF Yes then examine like this: <system.net> <mailsettings> <smtp from="test@par.com"> <network host="172.0.0.1 OR localhost" port="25" username="" password="" defaultcredentials="true" /> </smtp> </mailsettings> </system.net> OR try external SMTP Server of Gmail

                System.Net.Mail.SmtpClient email = new System.Net.Mail.SmtpClient();
                email.Host = "smtp.gmail.com";
                email.Port = 465 ;
                ............
                ............

                Parwej Ahamad R & D: REST services with WCF

                T Offline
                T Offline
                tina newcoder
                wrote on last edited by
                #7

                again SmtpException this time The operation has timed out. :confused: :confused: :confused:

                P 1 Reply Last reply
                0
                • T tina newcoder

                  again SmtpException this time The operation has timed out. :confused: :confused: :confused:

                  P Offline
                  P Offline
                  Parwej Ahamad
                  wrote on last edited by
                  #8

                  [Message Deleted]

                  T 1 Reply Last reply
                  0
                  • P Parwej Ahamad

                    [Message Deleted]

                    T Offline
                    T Offline
                    tina newcoder
                    wrote on last edited by
                    #9

                    Parwej Ahamad wrote:

                    which one you are using ?

                    anti-virus ? avg free !

                    P 1 Reply Last reply
                    0
                    • T tina newcoder

                      Parwej Ahamad wrote:

                      which one you are using ?

                      anti-virus ? avg free !

                      P Offline
                      P Offline
                      Parwej Ahamad
                      wrote on last edited by
                      #10

                      are you set on web.config file or using the Google SMTP server ?

                      Parwej Ahamad R & D: REST services with WCF

                      T 1 Reply Last reply
                      0
                      • P Parwej Ahamad

                        are you set on web.config file or using the Google SMTP server ?

                        Parwej Ahamad R & D: REST services with WCF

                        T Offline
                        T Offline
                        tina newcoder
                        wrote on last edited by
                        #11

                        Google SMTP server

                        P 1 Reply Last reply
                        0
                        • T tina newcoder

                          Google SMTP server

                          P Offline
                          P Offline
                          Parwej Ahamad
                          wrote on last edited by
                          #12

                          [Message Deleted]

                          T 1 Reply Last reply
                          0
                          • P Parwej Ahamad

                            [Message Deleted]

                            T Offline
                            T Offline
                            tina newcoder
                            wrote on last edited by
                            #13

                            Parwej Ahamad wrote:

                            Are you logged on any IM ?

                            -> na... code:

                            protected void Page_Load(object sender, EventArgs e)
                            {
                            string server;
                            server = "localhost";
                            // Specify the file to be attached and sent.
                            // This example assumes that a file named Data.xls exists in the
                            // current working directory.
                            string file = "data.xls";
                            file = Server.MapPath("~/data.xls");
                            // Create a message and set up the recipients.
                            MailMessage message = new MailMessage(
                            "apurvkolte@live.com",
                            "apurvkolte@gmail.com",
                            "Quarterly data report.",
                            "See the attached spreadsheet.");

                                    // Create  the file attachment for this e-mail message.
                                    Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
                                    // Add time stamp information for the file.
                                    ContentDisposition disposition = data.ContentDisposition;
                                    disposition.CreationDate = System.IO.File.GetCreationTime(file);
                                    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
                                    disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
                                    // Add the file attachment to this e-mail message.
                                    message.Attachments.Add(data);
                                    //Send the message.
                                    SmtpClient client = new SmtpClient();
                                    client.Host = "smtp.gmail.com";
                                    client.Port = 465;
                                    // Add credentials if the SMTP server requires them.
                                    client.Credentials = CredentialCache.DefaultNetworkCredentials;
                                    client.Send(message);
                                    // Display the values in the ContentDisposition for the attachment.
                                    ContentDisposition cd = data.ContentDisposition;
                                    Console.WriteLine("Content disposition");
                                    Console.WriteLine(cd.ToString());
                                    Console.WriteLine("File {0}", cd.FileName);
                                    Console.WriteLine("Size {0}", cd.Size);
                                    Console.WriteLine("Creation {0}", cd.CreationDate);
                                    Console.WriteLine("Modification {0}", cd.ModificationDate);
                                    Console.WriteLine("Read {0}", cd.ReadDate);
                                    Console.WriteLine("Inline {0}", cd.Inline);
                                    Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
                                    foreach (DictionaryEntry d in cd.Parameters)
                                    {
                                        Console.WriteLin
                            
                            T P 2 Replies Last reply
                            0
                            • T tina newcoder

                              Parwej Ahamad wrote:

                              Are you logged on any IM ?

                              -> na... code:

                              protected void Page_Load(object sender, EventArgs e)
                              {
                              string server;
                              server = "localhost";
                              // Specify the file to be attached and sent.
                              // This example assumes that a file named Data.xls exists in the
                              // current working directory.
                              string file = "data.xls";
                              file = Server.MapPath("~/data.xls");
                              // Create a message and set up the recipients.
                              MailMessage message = new MailMessage(
                              "apurvkolte@live.com",
                              "apurvkolte@gmail.com",
                              "Quarterly data report.",
                              "See the attached spreadsheet.");

                                      // Create  the file attachment for this e-mail message.
                                      Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
                                      // Add time stamp information for the file.
                                      ContentDisposition disposition = data.ContentDisposition;
                                      disposition.CreationDate = System.IO.File.GetCreationTime(file);
                                      disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
                                      disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
                                      // Add the file attachment to this e-mail message.
                                      message.Attachments.Add(data);
                                      //Send the message.
                                      SmtpClient client = new SmtpClient();
                                      client.Host = "smtp.gmail.com";
                                      client.Port = 465;
                                      // Add credentials if the SMTP server requires them.
                                      client.Credentials = CredentialCache.DefaultNetworkCredentials;
                                      client.Send(message);
                                      // Display the values in the ContentDisposition for the attachment.
                                      ContentDisposition cd = data.ContentDisposition;
                                      Console.WriteLine("Content disposition");
                                      Console.WriteLine(cd.ToString());
                                      Console.WriteLine("File {0}", cd.FileName);
                                      Console.WriteLine("Size {0}", cd.Size);
                                      Console.WriteLine("Creation {0}", cd.CreationDate);
                                      Console.WriteLine("Modification {0}", cd.ModificationDate);
                                      Console.WriteLine("Read {0}", cd.ReadDate);
                                      Console.WriteLine("Inline {0}", cd.Inline);
                                      Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
                                      foreach (DictionaryEntry d in cd.Parameters)
                                      {
                                          Console.WriteLin
                              
                              T Offline
                              T Offline
                              tina newcoder
                              wrote on last edited by
                              #14

                              i have copied it from msdn

                              1 Reply Last reply
                              0
                              • T tina newcoder

                                Parwej Ahamad wrote:

                                Are you logged on any IM ?

                                -> na... code:

                                protected void Page_Load(object sender, EventArgs e)
                                {
                                string server;
                                server = "localhost";
                                // Specify the file to be attached and sent.
                                // This example assumes that a file named Data.xls exists in the
                                // current working directory.
                                string file = "data.xls";
                                file = Server.MapPath("~/data.xls");
                                // Create a message and set up the recipients.
                                MailMessage message = new MailMessage(
                                "apurvkolte@live.com",
                                "apurvkolte@gmail.com",
                                "Quarterly data report.",
                                "See the attached spreadsheet.");

                                        // Create  the file attachment for this e-mail message.
                                        Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
                                        // Add time stamp information for the file.
                                        ContentDisposition disposition = data.ContentDisposition;
                                        disposition.CreationDate = System.IO.File.GetCreationTime(file);
                                        disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
                                        disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
                                        // Add the file attachment to this e-mail message.
                                        message.Attachments.Add(data);
                                        //Send the message.
                                        SmtpClient client = new SmtpClient();
                                        client.Host = "smtp.gmail.com";
                                        client.Port = 465;
                                        // Add credentials if the SMTP server requires them.
                                        client.Credentials = CredentialCache.DefaultNetworkCredentials;
                                        client.Send(message);
                                        // Display the values in the ContentDisposition for the attachment.
                                        ContentDisposition cd = data.ContentDisposition;
                                        Console.WriteLine("Content disposition");
                                        Console.WriteLine(cd.ToString());
                                        Console.WriteLine("File {0}", cd.FileName);
                                        Console.WriteLine("Size {0}", cd.Size);
                                        Console.WriteLine("Creation {0}", cd.CreationDate);
                                        Console.WriteLine("Modification {0}", cd.ModificationDate);
                                        Console.WriteLine("Read {0}", cd.ReadDate);
                                        Console.WriteLine("Inline {0}", cd.Inline);
                                        Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
                                        foreach (DictionaryEntry d in cd.Parameters)
                                        {
                                            Console.WriteLin
                                
                                P Offline
                                P Offline
                                Parwej Ahamad
                                wrote on last edited by
                                #15

                                Let me check on my machine ?

                                Parwej Ahamad R & D: REST services with WCF

                                T 1 Reply Last reply
                                0
                                • P Parwej Ahamad

                                  Let me check on my machine ?

                                  Parwej Ahamad R & D: REST services with WCF

                                  T Offline
                                  T Offline
                                  tina newcoder
                                  wrote on last edited by
                                  #16

                                  i am going to sleep now. we'll talk tomorrow ... bye gn

                                  P 1 Reply Last reply
                                  0
                                  • T tina newcoder

                                    i am going to sleep now. we'll talk tomorrow ... bye gn

                                    P Offline
                                    P Offline
                                    Parwej Ahamad
                                    wrote on last edited by
                                    #17

                                    Below given code are working fine on my machine. Note: Which I have mark as bold provide there your gmail id and password.

                                    MailMessage MyMailMessage=new MailMessage();
                                    MyMailMessage.From = new MailAddress("g.parwez@gmail.com");
                                    MyMailMessage.To.Add("g.parwez@gmail.com");
                                    MyMailMessage.Subject = "Parwej Testing !!!";
                                    MyMailMessage.Body = "This is the test text for Parwej Ahamad";
                                    SmtpClient SMTPServer=new SmtpClient("smtp.gmail.com");
                                    SMTPServer.Port = 587;
                                    SMTPServer.Credentials =new System.Net.NetworkCredential("yourgmaid", "yourgmailpassword");
                                    SMTPServer.EnableSsl = true;
                                    SMTPServer.Send(MyMailMessage);

                                    After that you can check your attachment code.

                                    Parwej Ahamad R & D: REST services with WCF

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups