zoukankan      html  css  js  c++  java
  • 邮件发送_文本发送

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Net.Mail;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace MyMail
    {
        public partial class Form1 : Form
        {
            public string smtp = "smtp.163.com";//这个是163的格式。
            public string from = "fromMail@163.com";//发件人邮箱
            public string pwd = "fromMailPwd";//发件人密码
            public string to = "toMail@163.com";//邮件接收人
            public string subject = "测试";//邮件标题
            public string body = "内容11111111111" +System.DateTime.Now;//邮件内容
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btnSend_Click(object sender, EventArgs e)
            {
                SendMail2();
            }
    
            public void SendMail2()
            {
                //创建smtpclient对象
                System.Net.Mail.SmtpClient client = new SmtpClient();
                client.Host = smtp;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(from, pwd);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
    
                //创建mailMessage对象 
                System.Net.Mail.MailMessage message = new MailMessage(from, to);
                message.Subject = subject;
                //正文默认格式为html
                message.Body = body;
                message.IsBodyHtml = true;
                message.BodyEncoding = System.Text.Encoding.UTF8;            
    
                try
                {
                    client.Send(message);                
                }
                catch (Exception ex)
                {
                   
                }
            }
        }
    }
  • 相关阅读:
    监控文件变化
    哈希+ LIst + 流文件 应用
    (转)Delphi版木马彩衣一个简单的花指令伪装器
    (转)TThread 详解
    遍历菜单
    哈希 + LIST简单应用(DELPHI)
    WINDOWS API速查
    ASP.NET 3.5的页面指令
    感冒怎么治?
    ASPNET应用程序文件夹
  • 原文地址:https://www.cnblogs.com/pnljs/p/3745448.html
Copyright © 2011-2022 走看看