美文网首页
C#发送电子邮件

C#发送电子邮件

作者: INSO8 | 来源:发表于2018-08-26 22:07 被阅读0次
            string send = txtSend.Text.Trim();//发件人邮箱地址
            string to = txtTo.Text.Trim();//收件人邮箱地址
            if (regex(send) && regex(to))//判断发件人邮箱地址&&收件人邮箱地址不为空
            {
                if (send != "" && to != "" && txtpwd.Text != "")
                {
                    DialogResult result = MessageBox.Show("确认发送", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    if (result == DialogResult.OK)
                    {
                        try
                        {
                            MailMessage mailMessage = new MailMessage();
                            mailMessage.From = new MailAddress(send);//发件人邮箱地址
                            mailMessage.To.Add(new MailAddress(to));//收件人邮箱地址
                            mailMessage.Subject =Convert.ToBase64String(Encoding.UTF8.GetBytes(txtSubject.Text));//对邮件主题进行编码
                            mailMessage.Body = Convert.ToBase64String(Encoding.UTF8.GetBytes(rtboxContent.Text));//对邮件内容进行编码
                            SmtpClient client = new SmtpClient();
                            client.Host = "smtp." + send.Substring(send.IndexOf("@") + 1);//邮箱的服务器的地址
                            client.EnableSsl = true;//是否加密连接
                            client.UseDefaultCredentials = false;//不和请求一起发送
                            client.Credentials = new NetworkCredential(send, txtpwd.Text);//验证发件人的身份
                            client.Send(mailMessage);//发送邮件
                            MessageBox.Show("发送成功", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("发送失败", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("发件人邮箱、发件人密码、收件人邮箱不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
            else
            {
                MessageBox.Show("请输入正确的电子邮件", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

相关文章

  • C#发送电子邮件

  • 发送测试电子邮件消息: 无法发送此邮件

    发送测试电子邮件消息: 无法发送此邮件。请在帐户属性中验证电子邮件地址。 响应服务器: 553 authenti...

  • python使用SMTP发送电子邮件

    python使用SMTP发送电子邮件 SMTP是发送邮件的协议,Pytho...

  • Outlook设置问题

    有关出现问题: 发送测试电子邮件消息: 无法发送此邮件。请在帐户属性中验证电子邮件地址。 解决方法:关闭webma...

  • SMTP简介

    电子邮件的 SMTP 协议 SMTP SMTP是电子邮件应用的核心,用于从发送方的邮件服务器发送报文到接收方的邮件...

  • JSP发送邮件实例

    在本章中,我们将讨论如何使用JSP发送电子邮件。要使用JSP发送电子邮件,应该在计算机上安装JavaMail AP...

  • SpringBoot实现发送电子邮件

    目录 电子邮件与Java发送邮件的历史 电子邮件原理电子邮件服务器电子邮箱邮件客户端邮件传输协议邮件格式电子邮件发...

  • 发送电子邮件

    使用apache.commons.mail来发送电子邮件 commons-email发送普通文本邮件 common...

  • Python实现发送邮件(实现单发/群发邮件验证码)

    Python smtplib 教程展示了如何使用 smtplib 模块在 Python 中发送电子邮件。 要发送电...

  • 电子邮件营销

    电子邮件营销的三种不同类型的电子邮件: 交易性广播触发电子邮件您发送的每种电子邮件最终都旨在以不同的方式为客户增加...

网友评论

      本文标题:C#发送电子邮件

      本文链接:https://www.haomeiwen.com/subject/mljaiftx.html