C# Asp.Net Send Mail

C# Asp.Net Send Mail

14. December 2009

Read this article in your language IT | EN | DE | ES

Merhaba arkadaşlar bu  örnek  dersimizde asp.net  bir web sayfada mail  send işlemi nasıl   oluşturulur görelim

ilk  önce  tablo yapımızı oluşturalım   örnek bir yapı  ben oluşturdum sizlerde  resimdeki  şablona  göre bir  tasarım  yaparsınız 

 

Gelelim şimdi  Code Behind Tarafına Kaynak  kodumuzu  bu  şekilde  yazıyoruz 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Windows;
using System.Windows.Forms;

namespace SendMail
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnsend_Click(object sender, EventArgs e)
        {
            //MailMessage message = new MailMessage();
            //message.To.Add(txtto.Text);
            ////example adres mail@mail.com
            //message.From = new MailAddress(txtfrom.Text);
            //message.Subject = txtsubject.Text;
            //message.Body = txtmessage.Text;

            if (rdhtml.Checked == true)
            {
                Html();
                MessageBox.Show("Mail Gönderildi");
                CleanTable();

            }

            else if (rdmetin.Checked == true)
            {
                Metin();

                MessageBox.Show("Mail Gönderildi");
                CleanTable();
            }

        }

        protected void rdhtml_CheckedChanged(object sender, EventArgs e)
        {

            Html();
        }

        void Html()
        {

            try
            {
                MailMessage message = new MailMessage();
                message.To.Add(txtto.Text);
                //example adres mail@mail.com
                message.From = new MailAddress(txtfrom.Text);
                message.Subject = txtsubject.Text;
                message.Body = txtmessage.Text;
                message.IsBodyHtml = true;
                //Attach file using FileUpload Control and put the file in memory stream

                if (ContentFile.HasFile)
                {
                    message.Attachments.Add(new Attachment(ContentFile.PostedFile.InputStream, ContentFile.FileName));
                    SmtpClient smtp = new SmtpClient();

                    //  smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
                    smtp.Host = txtsmtpserver.Text;
                    smtp.Credentials = new System.Net.NetworkCredential(txtusername.Text, txtpass.Text);
                    //"YourGmailID@gmail.com", "YourGmailPassword");

                    //Or your Smtp Email ID and Password
                    smtp.EnableSsl = true;
                    smtp.Send(message);


                }
            }
            catch (Exception ex)
            {

                Response.Write("</br> " + ex.Message);
            }

        }
        void Metin()
        {

            try
            {
                MailMessage message = new MailMessage();
                message.To.Add(txtto.Text);
                //example adres mail@mail.com
                message.From = new MailAddress(txtfrom.Text);
                message.Subject = txtsubject.Text;
                message.Body = txtmessage.Text;
                message.IsBodyHtml = false;
                //Attach file using FileUpload Control and put the file in memory stream

                if (ContentFile.HasFile)
                {
                    message.Attachments.Add(new Attachment(ContentFile.PostedFile.InputStream, ContentFile.FileName));
                    SmtpClient smtp = new SmtpClient();

                    //  smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
                    smtp.Host = txtsmtpserver.Text;
                    smtp.Credentials = new System.Net.NetworkCredential(txtusername.Text, txtpass.Text);
                    //"YourGmailID@gmail.com", "YourGmailPassword");

                    //Or your Smtp Email ID and Password
                    smtp.EnableSsl = true;
                    smtp.Send(message);
                }
            }
            catch (Exception ex)
            {

                Response.Write("</br> " + ex.Message);

            }

        }

        protected void rdmetin_CheckedChanged(object sender, EventArgs e)
        {
            Metin();
        }

        void CleanTable()
        {
            txtfrom.Text = "";
            txtmessage.Text = "";
            txtpass.Text = "";
            txtsmtpserver.Text = "";
            txtsubject.Text = "";
            txtto.Text = "";
            txtusername.Text = "";
        }

    }
}

Eh bu kadar yazdık size birde kaynak kod verelim :İndir

Evet arkadaşlar  sizlerde artık  asp.net tabanlı  sayfalar da  smtp  mail sistemi kullanarak   kullanıcılarınıza mail  gönderebilirsiniz   evet  bir örnek projenin daha sonuna gelmiş  olduk 

yeni bir örnek projede görüşmek üzere herkeze başarılar 

FacebookDigg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

ASP NET ,

Comments

12/23/2009 11:59:49 AM #
yararlı bilgiler için teşekkürler.
12/30/2009 5:45:22 PM #
I love reading your posts. I wish you a Happy New Year!
1/2/2010 6:35:07 PM #
wish you Merry Christmas
2/25/2010 6:09:49 PM #
Congratulations, this was really a interesting post. In theory I would like to write like this too. You need time to creat that brilliant and in addition lots of effort to write  a excellent article.
3/1/2010 10:37:25 PM #
Nice site site you have here, I love the design, Naruto is my favorite anime btw Smile
3/6/2010 10:08:49 PM #
Hi webmaster - This is by far the best looking site I’ve seen. It was completely easy to navigate and it was easy to look for the information I needed. Fantastic layout and great content! Every site should have that. Awesome job
3/7/2010 3:26:03 PM #
Thanks for this enlightening post. I am always looking for material on particular subjects and it's seldom far away on the interweb. I'll be coming back soon.
3/7/2010 8:55:17 PM #
thanks for this info taken ages to find this.
3/7/2010 11:16:15 PM #
Gorgeous article...
3/9/2010 1:30:47 PM #
I don't agree with everything in this summary, but you do make some very good points. I'm very interested in this subject and I myself do alot of research as well. Either way it was a well thoughtout and nice read so I figured I would leave you a comment. Feel free to check out my website sometime and let me know what you think.
3/9/2010 3:23:58 PM #
I was looking for new information and came to your website by using bing. You continue being a great source of information.
3/10/2010 12:05:09 AM #
I really liked this excellent blog post. Please keep them coming. Regards from Thomas...
3/10/2010 6:12:50 AM #
I am a frequent reader of your blog and just wanted to inform you that I really love your articles.
3/10/2010 9:48:20 AM #
I am a frequent reader of your articles and just wanted to let you know you that I really love your blog.
3/14/2010 11:59:53 PM #
Great post, thanks admin for shring this article. T'm searching for this article for several days, finally I got it !
3/16/2010 9:45:11 AM #
3/21/2010 5:39:16 PM #
We would be interested in advertising on this site. Can you please contact us? Thanks
3/22/2010 12:57:54 AM #
Nooooo! Pittsburgh lost to Xav
3/22/2010 7:25:41 AM #
Hi HI First time skipped here on your site, founde on Bing.
3/22/2010 5:01:25 PM #
How to subscribe by email?
3/22/2010 6:24:31 PM #
My husband and I have been looking for this info.  Wondering if you know of anyway to make bulk emails anonymous?
3/22/2010 7:45:12 PM #
When I return I will spend more time going through this site. you have so much to offer.
3/22/2010 9:22:29 PM #
Easily, the post is actually the best on this deserving topic. I fit in with your conclusions and will eagerly look forward to your upcoming updates. Just saying thanks will not just be sufficient, for the extraordinary lucidity in your writing.
3/23/2010 1:48:42 AM #
billy cyrus phone number
3/31/2010 3:01:39 AM #
Great post.  Can I ask you a question?  I want to start a blog as well that is why I was searching on the internet for blogs to use as examples, do you find you have to be perfect in your grammar to have people like what you write?  I have been told I write like I speak, so I was wondering if that was a bad thing.
4/2/2010 11:08:29 PM #
My family is planning a vacation - we have two teenagers who love the trees, animals, riding quadrunners, snorkeling. We would ideally like to rent a house there as we may be joined by another family. Any suggestions would be appreciated and thank you!
4/3/2010 9:14:39 PM #
Seems cool!  Certainly opportune to find something with quality.
4/4/2010 3:47:42 AM #
Any disadvantages of owning a cockapoo, my kids really want one?
4/4/2010 7:57:29 AM #
According to a swedish  forum, rejoy bloggen,  the new iPad has been hacked. Geohot, who is known for various reasons, says his still unnamed jailbreak will likely function on  iPad as well. In case this is true it is absolutely no good news for Apple since their latest, predicted, milestone hasnt even been released yet.
4/4/2010 12:22:04 PM #
Oh.. that was interesting that my comment doesnt display. Despite I want to tell that it's well to see that someone else also exposed this as I had trouble locating the similar info elsewhere. By the way, fascinating article. Much of the people don't think that all sites should have comments section. On the other hand I believe that reader comments specify a blog. In short thanks a lot for letting us writing on this established page. Regards.
4/5/2010 9:38:58 PM #
I was researching small solar panel data and luckily found this post.  I found similar websites, like www.propeller.com/.../ that help you install your own solar panels but I need to find out where to get the photovoltaic or pv panels.
4/5/2010 10:00:55 PM #
Fantastic post! wonderful blog
4/6/2010 4:42:55 PM #
In order to transform your good blog into a major and extraordinary blog, you must continually provide content that Internet visitors want to use when they travel throughout the online world.
4/7/2010 12:13:35 AM #
By far the most concise and up to date information I found on this topic. Sure glad that I navigated to your page by accident. I’ll be subscribing to your feed so that I can get the latest updates. Appreciate all the information here
4/7/2010 8:34:50 AM #
Great site. I like the way you explain everything without using complicated terms.
4/7/2010 7:24:31 PM #
I am attempting to read the intact article but can only get middle. At the median point, everything seems to get interrupt. You should have a look at your stylesheet and make sure everythings unscathed. Smile
4/11/2010 8:53:53 PM #
Hey blog muy bonito!! El hombre .. Beautiful .. Amazing .. Voy a su favorito post  y tomar la alimenta también ...
4/13/2010 9:40:34 AM #
i am subscribing. thanks
4/16/2010 5:29:33 PM #
There is obviously a lot to know about this.  
4/18/2010 10:05:33 PM #
My close friend and I had been arguing about an issue identical to this! Now I know that I appeared to be correct. Thank you for the information you published.
4/21/2010 11:52:03 AM #
afaceri online - your online bussiness
4/27/2010 7:42:03 PM #
i am subscribing. thanks
5/5/2010 5:45:11 PM #
Loving this the post as it is in reality the sweetest on this valuable topic. I agree with your conclusions and will thirstily look forward to your upcoming updates. Saying thanks will not just be enough, for the wonderful clarity in your writing. I will at once grab your rss feed to stay informed of any updates.
5/6/2010 1:20:22 AM #
An online forex broker will essentially provide you with similar review, difference is that they'll provide you with economic indicators that might alter the price of a currency, because that is what's being traded here. An online broker have better access to information and the ability to disperse these information faster, and thus providing you with more timely and valuable cues as to when to buy and sell.
5/7/2010 5:17:56 AM #
Hi everyone. This weblog was fantastic! An abundance of awesome data and inspiration. Keep 'em coming... u all do such a necessary work at writing... can't tell you how much I, for one appreciate all you do! asp.net asp.net asp.net ROCKS
5/9/2010 1:03:40 PM #
Excellent site, where did you come up with the information in this posting? I'm pleased I found it though, ill be checking back soon to see what other articles you have.
5/11/2010 12:07:10 AM #
Have you thought about to adding some sort of bookmarking buttons or links to your posts? It will be simpler for me to bookmark such a good site.
5/14/2010 9:29:53 PM #
This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.
5/17/2010 5:51:08 PM #
Hello my blogger, your blogging page is really filled with good posts, but what the aspx end of each site intends? I only know html and xml. Is aspx dangerous?
5/21/2010 5:10:13 PM #
Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that. We got a good book on that matter from our local library and most books where not as influensive as your information. I am very glad to see such informat
5/23/2010 5:42:57 AM #
Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I'm more of a visual learner,I found that to be more helpful well let me know how it turns out
5/23/2010 12:17:38 PM #
Awesome! Not clear for me, how frequently you’d updating your site?
6/1/2010 12:41:25 AM #
I'm pretty fascinated with GPS stuff. This will now be the start of my 3rd hour looking through blogs and numerous sites doing some research and learning more prior to I go out and buy anything.
6/2/2010 5:56:27 AM #
wow... what can i say
6/3/2010 4:05:21 PM #
Anatole France used to say that we all know that art is not truth. Art is a lie that makes us realize the truth, at least the truth that is given to us to understand. .Lauren
6/3/2010 11:11:45 PM #
This is a very fascinating post, I was looking for this knowledge. Just so you know I located your webpage when I was checking for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.
6/4/2010 8:58:32 PM #
The post is actually the freshest on this precious topic. I concur with your conclusions and will eagerly look forward to your future updates. Saying thanks will not just be adequate, for the wonderful lucidity in your writing.
Jen
6/4/2010 11:27:35 PM #
Anybody try the Lynx alpha yet? I'm tempted to download it, want to hear any thoughts
6/6/2010 11:26:02 AM #
Hey... I don't know if you've been making changes, but your pages aren't displaying correctly for me. The edges of the text are running into each other. It wasn't like this Monday. I don't know if it's my end or if you've made a change... Just thought you might want to look at it. Thanks! Modesto Fulcher

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Sayfa 0.015625 saniyede yuklendi.