0
点赞
收藏
分享

微信扫一扫

C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客

王小沫 2022-04-02 阅读 32

C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客_wpf​​


C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客_c#_02​​


C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客_stack_03​​


C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客_aws_04​​


C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客_wpf_05​​


C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客_wpf_06​​


C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客_wpf_07​​


C#编程-140:Net.Mail类发送邮件_彭世瑜_新浪博客_wpf_08​​


  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net.Mail;
  10. namespace MailTest
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void btnSend_Click(object sender, EventArgs e)
  19. {
  20. MailMessage mail = new MailMessage();
  21. string myEmail = txtAccount.Text;
  22. string myPwd = txtPassword.Text;
  23. mail.BodyEncoding = System.Text.Encoding.UTF8;
  24. mail.IsBodyHtml = true;
  25. mail.From = new MailAddress(myEmail);
  26. mail.To.Add(new MailAddress(txtAccept.Text));
  27. mail.Subject = txtSubject.Text;
  28. mail.Body = txtBody.Text;
  29. mail.BodyEncoding = Encoding.UTF8;
  30. SmtpClient client = new SmtpClient(txtServer.Text);
  31. client.UseDefaultCredentials = false;
  32. client.Credentials = new System.Net.NetworkCredential(myEmail.Substring(0,myEmail.IndexOf('@')),myPwd);
  33. client.DeliveryMethod = SmtpDeliveryMethod.Network;
  34. try
  35. {
  36. client.Send(mail);
  37. MessageBox.Show("发送成功!");
  38. txtSubject.Text = null;
  39. txtBody.Text = null;
  40. }
  41. catch (Exception ex)
  42. {
  43. MessageBox.Show(ex.Message);
  44. }
  45. }
  46. }
  47. }



举报

相关推荐

0 条评论