163及qq邮箱发送

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //public static string CreateTimeoutTestMessage(string server)
        //{
        //    string Success = "发送成功";
        //    try
        //    {
        //        string _to = "[email protected]";
        //        string _from = "[email protected]";
        //        string _subject = "Using the new SMTP client.";
        //        string _body = @"Using this new feature, you can send an e-mail message from an application very easily.";
        //        MailMessage message = new MailMessage();
        //        message.From = new MailAddress(_from);
        //        //可以利用MailMessage.To.Add方法增加要发送的邮件地址
        //        message.To.Add(new MailAddress("[email protected]"));
        //        message.To.Add(new MailAddress(_to));
        //        message.Subject = _subject;
        //        message.Body = _body;

        //        //添加附件
        //        Attachment a = new Attachment(@"C:/Users/Administrator/Desktop/kk.txt");
        //        message.Attachments.Add(a);
        //        //设置邮箱的地址或IP
        //        SmtpClient client = new SmtpClient(server);
        //        //设置邮箱端口,pop3端口:110, smtp端口是:25
        //        client.Port = 25;

        //        //设置超时时间
        //        client.Timeout = 9999;

        //        //要输入邮箱用户名与密码  

        //        client.Credentials = new NetworkCredential("[email protected]", "zddszx");
        //        client.Send(message);
        //    }
        //    catch (Exception ex)
        //    {
        //        Success = ex.ToString();
        //    }
        //    return Success;
        //}

        private void button1_Click(object sender, EventArgs e)
        {
            string fuwuqi = textBox1.Text;
            string zhanghao = textBox2.Text;
            string mima = textBox3.Text;
            string dizhi = textBox4.Text;
            string biaoti = textBox5.Text;
            string neirong = textBox6.Text;
            SendMail(fuwuqi, zhanghao, mima, dizhi, biaoti, neirong);
        }
        public static void SendMail(string fuwuqi, string zhanghao, string mima, string dizhi, string biaoti, string neirong)
        {
            SmtpClient client = new SmtpClient(fuwuqi);    //邮件类,造一个对象client
            client.Credentials = new System.Net.NetworkCredential(zhanghao, mima);  //验证身份,通过发件人的地址和密码
            client.DeliveryMethod = SmtpDeliveryMethod.Network;  //指定如何发送电子邮件
            System.Net.Mail.MailMessage message = new MailMessage(zhanghao, dizhi, biaoti, neirong);
            message.BodyEncoding = System.Text.Encoding.UTF8;  //字符编码为Utf8
            message.IsBodyHtml = true;  //发送格式为html格式
            try
            {
                client.Send(message);  //讲指定的邮件发送到SMTP服务器以便传递
                MessageBox.Show("发送成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误信息:" + ex.Message, "错误");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "smtp.163.com";
            textBox2.Text = "[email protected]";
            textBox3.Text = "zddszx";
            textBox4.Text = "[email protected]";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string fuwuqi = textBox1.Text;   //服务器
            string mima = textBox3.Text;
            string biaoti = textBox5.Text;    //邮件标题
            string neirong = textBox6.Text;   //邮件的内容

            for (int i = 0; i < listView1.SelectedItems.Count; i++)
            {
                string dizhi = listView1.SelectedItems[i].SubItems[1].ToString();//收件地址
                string zhanghao = listView1.SelectedItems[i].SubItems[2].ToString();
                //string mima = listView1.SelectedItems[i].SubItems[3].ToString();
                SendMail(fuwuqi, zhanghao, mima, dizhi, biaoti, neirong);  //调用发送邮件方法需要输入六个参数
                System.Threading.Thread.Sleep(2000);
            }
        }
        int a = 0;
        private void button3_Click(object sender, EventArgs e)
        {
            listView1.Columns.Clear();
            listView1.Columns.Add("编号");
            listView1.Columns.Add("收件邮箱", 120);
            listView1.Columns.Add("发件箱", 120);
            //listView1.Columns.Add("密码", 120);
            listView1.GridLines = true;
            for (int i = 1; i <= 100; i++)
            {
                listView1.Items.Add("" + i);
            }
            listView1.Items[a].SubItems.Add(textBox4.Text);
            listView1.Items[a].SubItems.Add(textBox2.Text);
            listView1.Items[a].SubItems.Add(textBox3.Text);
            a++;
        }
    }
}

  

发送邮件的邮箱要先启用SMTP,否则不能发送
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net.Mail;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnfasong_Click(object sender, EventArgs e)
        {
            try
            {
                MailAddress EmailFrom = new MailAddress(txtsend.Text);  //发件人邮箱地址
                string EmailTo = txtto.Text;  //收件人邮箱地址
                string Emailbiaoti = txtbiaoti.Text; //邮件标题
                string Emailneirong = txtnrong.Text; //邮件内容
                fasong(EmailTo, Emailbiaoti, Emailneirong, EmailFrom);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void fasong(string EmailTo, string Emailbiaoti, string Emailneirong, MailAddress EmailFrom)
        {

            try
            {
                txtto.Text = txtto.Text.Replace(" ", "");//去除空格
                txtto.Text = txtto.Text.Trim();
                MailMessage email = new MailMessage();
                email.From = EmailFrom;
                email.To.Add(EmailTo);//收件人邮箱地址可以是多个以实现群发
                email.Subject = Emailbiaoti;//获取邮件的标题
                email.Body = Emailneirong;//获取邮件的内容
                email.IsBodyHtml = false; //是否为html格式
                email.Priority = MailPriority.Normal;  //发送邮件的优先等级
                SmtpClient sc = new SmtpClient();//允许使用SMTP协议发送邮件
                sc.Host =txthost.Text;//指定发送邮件的服务器地址
                sc.Port = 25;//指定发送邮件端口
                sc.DeliveryMethod = SmtpDeliveryMethod.Network;//指定如何发送电子邮件,通过网络发送到SMTP服务器
                sc.UseDefaultCredentials = false;//是否随请求一起发送
                sc.EnableSsl = false;//安全连接设置
                sc.Credentials = new System.Net.NetworkCredential(txtsend.Text, txtsenderpwd.Text); //指定登录服务器的用户名和密码
                sc.Send(email);
                MessageBox.Show("发送成功!");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txthost.Text = "smtp.qq.com";
            txtsend.Text = "[email protected]";
            txtsenderpwd.UseSystemPasswordChar = true;
        }
    }
}

  

时间: 2024-09-27 01:45:04

163及qq邮箱发送的相关文章

教你怎么写电子邮箱格式?以163和QQ邮箱为例

电子邮箱格式怎么写,不少开始接触邮件的朋友经常问这样的问题,其实写邮件很简单,现在用的最多的是网易163邮箱和QQ邮箱.新浪邮箱,下面做下演示操作,教你怎么写电子邮箱格式.电子邮箱的格式通常为:.其中username为用户名(邮箱帐户名),"@"后面的是域名.如腾讯的邮箱格式一般为:(xxxx为QQ号码).电子邮箱格式中的@符号是同时按shift+数字键2打出来的.刚用电脑的朋友可能一下不知道.下面本文中就简单的说下网易163和QQ邮箱的格式怎么写,怎么发邮件,其它电子邮件方法也与此类

通过java给qq邮箱发送信息

通过java程序给qq邮箱发送信息. 1.第一步:下载mail的jar包:javax.mail.jar 下载地址:https://javaee.github.io/javamail/#Latest_News 2.直接使用下面的代码 public static void sendMessages() { try { //创建Properties 类用于记录邮箱的一些属性 final Properties props = new Properties(); //表示SMTP发送邮件,必须进行身份验证

javaMail操作QQ邮箱发送邮箱 Demo

最近用到想给项目中加一个功能,就是当项目中某些模块发生异常,在捕获异常后不仅仅写日志抛异常等!还要追加一个发送邮件给该模块的负责人,方便运维定位问题: maven管理的配置: <!-- 邮件 --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.7</version> </depe

QQ邮箱发送信息

#以下库为python自带的库,不需要进行安装 #邮件发信动作 import smtplib #构造邮件内容 from email.mime.text import MIMEText #构造邮件头 from email.header import Header #发信方:发信邮箱 和授权码 #发信邮箱 from_addr="54****[email protected]" #授权码 password="q*******dba" #收信方:收信邮箱 to_addr=&

qq邮箱发送

454 Authentication failed, please open smtp flag first!用QQ邮箱测试报错 我用QQ邮箱测试javamail发送邮件的功能,用户名密码设置正确,却总是发不出邮件. 开启下QQ邮箱的smtp服务器设置即可.

使用qq邮箱发送html格式的邮件

import smtplib   from email.mime.text import MIMEText   mailto_list=["[email protected]","[email protected]"]  mail_host="smtp.qq.com"  #设置服务器 mail_user="[email protected]"   #用户名 mail_pass="xxx"   #密码    

C#使用QQ邮箱发送,出现mail from address must be same as authorization user异常

1.未开启pop3或者smtp 2.在使用第三方客户端时,邮箱登录密码不是"登录密码",应该是生成的授权码. 如图:

Python实现QQ邮箱发送

具体参考代码: #!/usr/bin/env python # encoding: utf-8 import smtplib from email.mime.text import MIMEText class MyEmail:     def __init__(self, subject, body):         self.subject = subject         self.body = body         self.host = 'smtp.qq.com'       

QQ邮箱发送邮件,出现mail from address must be same as authorization user错误

之前做的一个系统,有个发送邮件的功能,一直能正常使用,今天同事说QQ邮箱发送不了. 立马着手调试,发现服务器一直出现“mail from address must be same as authorization user”的错误,网上很多人说是“POP3/SMTP服务”没有开启,登录邮箱查看,发现该服务是开启的. 百思不得其解时,另一个同事说他用另一个QQ邮箱测试,邮件能正常发送,立即进入邮箱对比,发现他的QQ邮箱设置了“独立密码”,联想到抛出的错误提示,顿时大悟,设置独立密码,程序发送邮件时