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)
                {
                   
                }
            }
        }
    }
  • 相关阅读:
    显示等待WebDriverWait
    MySQL添加注释
    linux
    linux时区问题
    CentOS禁用笔记本touchpad
    Mysql事务隔离级别
    IDEA集成有道翻译插件/maven帮助插件/mybatis插件
    SVN服务器的搭建和使用
    IntelliJ IDEA工具的安装使用
    IntelliJ IDEA的使用操作链接
  • 原文地址:https://www.cnblogs.com/pnljs/p/3745448.html
Copyright © 2011-2022 走看看