• C# 发送邮件


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Net;
    using System.Net.Mail;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;


    namespace SendEmailExam
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                txtContent.Text = "<h1>Hello</h1>";
                txtTo.Text = "xxx@163.com";
                txtSubject.Text = "Hello";
                txtCC.Text = "xxx@126.com;xxx@163.com";
            }


            private void btnSend_Click(object sender, EventArgs e)
            {
                SmtpClient sc = new SmtpClient();
                NetworkCredential cred = new NetworkCredential("admin", "admin");
                sc.Credentials = cred;
                sc.Host = "smtp.163.com";
                MailMessage mm = new MailMessage();
                mm.From = new MailAddress("xxx@163.com", "xxx");
                mm.Sender = new MailAddress("xxx@163.com","xxx");
                string[] tos = txtTo.Text.Split(';');
                foreach (string item in tos)
                {
                    mm.To.Add(new MailAddress(item));
                }
                string[] ccs = txtCC.Text.Split(';');
                foreach (string item in ccs)
                {
                    mm.CC.Add(new MailAddress(item));
                }
                mm.Subject = txtSubject.Text;
                mm.Body = txtContent.Text;
                mm.IsBodyHtml = true;
                mm.Priority = MailPriority.High;
                mm.Attachments.Add(new Attachment(txtAccessory.Text));
                sc.Send(mm);
            }

            private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect = false;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    txtAccessory.Text = ofd.FileName;
                }
            }
        }
    }
  • 相关阅读:
    Tweet button with a callback – How to?
    Get URL parameters & values with jQuery
    javascript 原生 cookie 处理
    sae crop 文档
    javascript获取地址栏参数/值
    Google Calendar(日历)设置农历生日提醒
    字符串转换成JSON(js)
    The ultimate jQuery Plugin List(终极jQuery插件列表)
    用 javascript 判断 IE 版本号
    Unable to start services through AMBARI UI
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434766.html
Copyright © 2020-2023  润新知