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

    //判断QQ是否在线 

    private void simpleButton1_Click(object sender, EventArgs e)
            {
                string ssnum = "1000000";

                string eenum = "999999999";


                Int32 startnum = Int32.Parse(ssnum);

                Int32 endnum = Int32.Parse(eenum);
                Random rd = new Random();

                Int32 i = rd.Next(startnum, endnum);

                WebClient wc = new WebClient();

                wc.Encoding = Encoding.GetEncoding("GB2312");

                byte[] temp = wc.DownloadData("http://wpa.qq.com/pa?p=2:306476937:41");
                if (temp.Length == 3327)
                {

                    //这里是QQ在线执行的代码

                }


            }

    //发送邮件

            private void simpleButton2_Click(object sender, EventArgs e)
            {
                try
                {
                    MailAddress Messagefrom = new MailAddress(this.txtSend.Text, "C#仰望着");  //发件人邮箱地址
                    string MessageTo = this.txtTo.Text;  //收件人邮箱地址
                    string MessageSubject = this.txtSubject.Text;        //邮件主题
                    string MessageBody = this.txtBody.Text;    //邮件内容
                    Send(MessageTo, MessageSubject, MessageBody, Messagefrom);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }

            public void Send(string MessageTo, string MessageSubject, string MessageBody, MailAddress Messagefrom)
            {

                try
                {
                    txtTo.Text = txtTo.Text.Replace(" ", "");//去除空格
                    txtTo.Text = txtTo.Text.Trim();
                    txtTo.Text = txtTo.Text.Replace((char)13, (char)0);
                    MailMessage email = new MailMessage();
                    email.From = Messagefrom;
                    email.To.Add(MessageTo);//收件人邮箱地址可以是多个以实现群发
                    email.Subject = MessageSubject;
                    email.Body = MessageBody;
                    email.IsBodyHtml = false; //是否为html格式 
                    email.Priority = MailPriority.Normal;  //发送邮件的优先等级
                    SmtpClient sc = new SmtpClient();
                    sc.Host = cbHost.Text;              //指定发送邮件的服务器地址或IP
                    sc.Port = 25;//指定发送邮件端口
                    sc.DeliveryMethod = SmtpDeliveryMethod.Network;//指定如何发送电子邮件
                    sc.UseDefaultCredentials = false;//是否随请求一起发送
                    sc.EnableSsl = false;//安全连接设置
                    sc.Credentials = new System.Net.NetworkCredential(this.txtSend.Text, this.txtSenderPwd.Text); //指定登录服务器的用户名和密码
                    sc.Send(email);
                    MessageBox.Show("邮件发送成功!", "系统提示");
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }

            }

  • 相关阅读:
    Linux 信号signal处理机制
    va_start、va_arg、va_end、va_copy 可变参函数
    辛星笔记——VIM学习篇(推荐阅读)
    每个程序员都应该读的书
    igmpproxy源代码学习——配置信息加载 loadConfig
    windows下gvim搭建IDE
    插入排序与循环不变式
    6个变态的C语言程序
    安卓原生百度地图(5)导航和语音播报
    安卓原生百度地图(4)路线规划
  • 原文地址:https://www.cnblogs.com/xz4062006/p/4244446.html
Copyright © 2011-2022 走看看