Use. NET send an e-mail applet sample

Source: Internet
Author: User
Tags tostring mailmessage net send smtpclient

This article is mainly to. NET how to implement send e-mail as a sample analysis, so there are many involved in the sample program. None of the content outside the Net.mail was done. Recently more busy not too much time to improve its function, interested friends can download the source code to improve the next. This is not a big software, it is not a special thing, I write this article is to let everyone learn together. NET to send the realization of e-mail, I hope this article can help to do not know how to achieve the message to send friends, for has been or this aspect of the ancestors of the cattle to see this article please leave valuable suggestions.

This procedure is used. NET Framework of mail classes to complete the delivery of mail, inside the recipient mail address I used the XML to store, this involves the XML read and write operations, in addition to the attachment of the application of the dialog box. To analyze this, first we need to refer to the appropriate namespace, namely:

1using System.Net.Mail;
2using System.Xml;
3using System.IO;

First, take a look at the final operating effect (you can understand the structure of the program from the interface layer)

Two. Here's a look at the code that implements the email function, as shown in the following code:

private void Btnsend_click (object sender, EventArgs e) {System.Net.Mail.SmtpClient client = new SmtpClient (); Client. Host = This.tbSmtpServer.Text.ToString (); The host name or IP address client of the SMTP transaction used to send the message.
      useDefaultCredentials = false; NetworkCredential (sender email address, sender's email password) client. Credentials = new System.Net.NetworkCredential (this.tbSender.Text.ToString (), This.tbsend
      ErPassWord.Text.ToString ()); Client.  Deliverymethod = Smtpdeliverymethod.network; e-mail messages are sent over the network to the SMTP server//mailmessage (sender address, recipient address) MailMessage message = new MailMessage (this.tbSender.Text.To
      String (), this.lbQuester.SelectedItem.ToString ()); Message.  Subject = This.tbTitle.Text.ToString (); Mail subject message.   BODY = this.tbContext.Text.ToString (); Message content. bodyencoding = System.Text.Encoding.UTF8; The encoding of the message body.
  
      Isbodyhtml = true; The following is an attachment process string attahmentname=this.tbatrrac.tExt. Trim ().
      ToString (); if (!string. Equals (attahmentname, null) &&!string. Equals (Attahmentname, "")) {Attachment data = new Attachment (Attahmentname, System.Net.Mime.MediaTypeNames.
        Application.octet); Message.
      Attachments.Add (data); ///Send mail try {client.
        Send (message);
      MessageBox.Show ("e-mail sucessfully send to:" + this.lbQuester.SelectedItem.ToString ()); catch (Exception ex) {MessageBox.Show ("e-mail send fail!" + ex.)
      ToString ()); }     }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.