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. General Programming
  3. C#
  4. Sending a E-mail in C#

Sending a E-mail in C#

Scheduled Pinned Locked Moved C#
csharpquestionsysadminhelp
13 Posts 4 Posters 1 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.
  • I Offline
    I Offline
    imnotso
    wrote on last edited by
    #1

    Hi, Can someone try to tell me the definitive (like, yeah) way of sending a mail in c# from my website. I'm .NET2, Visual Sudio 2005 and have a 3 simple textboxs and a send button on my site for people to get in touch. I want it to send me the text1 as a subject, text2 as the body, text3 as their mail address (which they have manually typed in) Obviously I've been round the web..... private void Button1_Click(object sender, System.EventArgs e) { MailMessage mail = new MailMessage(); mail.To = txtTo.Text; mail.From = txtFrom.Text; mail.Subject = txtSubject.Text; mail.Body = txtBody.Text; SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(mail); } these seem out of date, and how do I test locally on my machine? Do I put 'localhost' as my SMTP server? until it goes live? Any help would be great. Thanks Harvey

    N R 2 Replies Last reply
    0
    • I imnotso

      Hi, Can someone try to tell me the definitive (like, yeah) way of sending a mail in c# from my website. I'm .NET2, Visual Sudio 2005 and have a 3 simple textboxs and a send button on my site for people to get in touch. I want it to send me the text1 as a subject, text2 as the body, text3 as their mail address (which they have manually typed in) Obviously I've been round the web..... private void Button1_Click(object sender, System.EventArgs e) { MailMessage mail = new MailMessage(); mail.To = txtTo.Text; mail.From = txtFrom.Text; mail.Subject = txtSubject.Text; mail.Body = txtBody.Text; SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(mail); } these seem out of date, and how do I test locally on my machine? Do I put 'localhost' as my SMTP server? until it goes live? Any help would be great. Thanks Harvey

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      imnotso# wrote:

      MailMessage mail = new MailMessage(); mail.To = txtTo.Text; mail.From = txtFrom.Text; mail.Subject = txtSubject.Text; mail.Body = txtBody.Text; SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(mail);

      This is obsolete now. Use classes in System.Net.Mail namespace. You can configure System.Net.Mail settings on the app.config file and put the server name as localhost. Stop local SMTP server and set mail delivery type as PickupDirectoryFromIis which will deliver mails to the pickup directory.

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      I 1 Reply Last reply
      0
      • N N a v a n e e t h

        imnotso# wrote:

        MailMessage mail = new MailMessage(); mail.To = txtTo.Text; mail.From = txtFrom.Text; mail.Subject = txtSubject.Text; mail.Body = txtBody.Text; SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(mail);

        This is obsolete now. Use classes in System.Net.Mail namespace. You can configure System.Net.Mail settings on the app.config file and put the server name as localhost. Stop local SMTP server and set mail delivery type as PickupDirectoryFromIis which will deliver mails to the pickup directory.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        I Offline
        I Offline
        imnotso
        wrote on last edited by
        #3

        Thanks for that, In the new classes I cannot find where I specify the SMTP server name. Any ideas? Harvey

        I 1 Reply Last reply
        0
        • I imnotso

          Thanks for that, In the new classes I cannot find where I specify the SMTP server name. Any ideas? Harvey

          I Offline
          I Offline
          imnotso
          wrote on last edited by
          #4

          Plus 'localhost' always returns an error.

          C 1 Reply Last reply
          0
          • I imnotso

            Plus 'localhost' always returns an error.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Then I guess you found where to put it ? You need an actual mail server, in order to send mail.

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            I 1 Reply Last reply
            0
            • C Christian Graus

              Then I guess you found where to put it ? You need an actual mail server, in order to send mail.

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              I Offline
              I Offline
              imnotso
              wrote on last edited by
              #6

              Yeah, thanks. Why is everyone mentioning 'localhost' if it's not a vaible option i wonder? Can I just use any server until I put it live? Thanks

              C I 2 Replies Last reply
              0
              • I imnotso

                Yeah, thanks. Why is everyone mentioning 'localhost' if it's not a vaible option i wonder? Can I just use any server until I put it live? Thanks

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                It's possible to set up a mail server on our local machine. You can put whatever you like, but it won't work, obviously.

                Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                1 Reply Last reply
                0
                • I imnotso

                  Yeah, thanks. Why is everyone mentioning 'localhost' if it's not a vaible option i wonder? Can I just use any server until I put it live? Thanks

                  I Offline
                  I Offline
                  imnotso
                  wrote on last edited by
                  #8

                  I'm not sure how it can be tested then without putting it live, that cannot be right surely?

                  C N 2 Replies Last reply
                  0
                  • I imnotso

                    I'm not sure how it can be tested then without putting it live, that cannot be right surely?

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    How do you hope to send mail, without a mail server ? You cannot. I don't see the issue, your mail server is not 'live', it's the server that sends your mail ( i.e. you can use the mail server from your ISP, the one that your Outlook uses ).

                    Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                    1 Reply Last reply
                    0
                    • I imnotso

                      I'm not sure how it can be tested then without putting it live, that cannot be right surely?

                      N Offline
                      N Offline
                      N a v a n e e t h
                      wrote on last edited by
                      #10

                      Just for testing purpose you can use localhost as server and delivery method as Pickup directory. So all the mails sent are kept in pickup directory as outlook file format. You can goto that directory and easily check the mail. Once you are ready to release the application, change delivery method to Network and specify valid SMTP server details and credentials. Read details about SMTPClient here[^]. Read and excellent FAQ on System.Net.Mail here[^]. Also this[^] explains how to configure your application configuration file.

                      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                      I 1 Reply Last reply
                      0
                      • N N a v a n e e t h

                        Just for testing purpose you can use localhost as server and delivery method as Pickup directory. So all the mails sent are kept in pickup directory as outlook file format. You can goto that directory and easily check the mail. Once you are ready to release the application, change delivery method to Network and specify valid SMTP server details and credentials. Read details about SMTPClient here[^]. Read and excellent FAQ on System.Net.Mail here[^]. Also this[^] explains how to configure your application configuration file.

                        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                        I Offline
                        I Offline
                        imnotso
                        wrote on last edited by
                        #11

                        Thank you, I thought it was possible. many thanks again....

                        N 1 Reply Last reply
                        0
                        • I imnotso

                          Thank you, I thought it was possible. many thanks again....

                          N Offline
                          N Offline
                          N a v a n e e t h
                          wrote on last edited by
                          #12

                          You are welcome.

                          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                          1 Reply Last reply
                          0
                          • I imnotso

                            Hi, Can someone try to tell me the definitive (like, yeah) way of sending a mail in c# from my website. I'm .NET2, Visual Sudio 2005 and have a 3 simple textboxs and a send button on my site for people to get in touch. I want it to send me the text1 as a subject, text2 as the body, text3 as their mail address (which they have manually typed in) Obviously I've been round the web..... private void Button1_Click(object sender, System.EventArgs e) { MailMessage mail = new MailMessage(); mail.To = txtTo.Text; mail.From = txtFrom.Text; mail.Subject = txtSubject.Text; mail.Body = txtBody.Text; SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(mail); } these seem out of date, and how do I test locally on my machine? Do I put 'localhost' as my SMTP server? until it goes live? Any help would be great. Thanks Harvey

                            R Offline
                            R Offline
                            RedHotFunk
                            wrote on last edited by
                            #13

                            I have a working version of an email client I made using smtp for C#. If you still need it, I can send you my sample code. As well, I would like to tell you that the server you are using is also important. I'm going to presume that you are going to use a free server, so your best bet would most likely be using Googlemail's smtp, since you actually forward your mail to their ports. As well, what you had before was to simple a method, if you're using an smtp server, you're going to have to authenticate each request, meaning that you'll also have to send your email's password.

                            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