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
  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 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