本文介绍了确保我的代码正确:从winform应用程序发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好。当我点击我的winform应用程序中的发送按钮时,他们告诉我电子邮件已成功发送。实际上,当我登录我的电子邮件时,我没有任何消息。那么问题出在哪里?再次感谢您的回答:)hello. when I click the send button in my winform app they tell me that the email was successfully sent. ut actually when I login to my email, I have no message. so where is the problem? thank you again for answering:)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.Net.Mail;using System.Net;using System.Text.RegularExpressions;namespace greeting_card{ public partial class Form3 : Form { MailMessage message; SmtpClient smtp; private bool IsValidEmail(string emailAddress) { return Regex.IsMatch(emailAddress, @"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"); } private void smtp_SendCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Cancelled == true) MessageBox.Show("Email sending cancelled!"); else MessageBox.Show("Email sent sucessfully!"); } public Form3() { InitializeComponent(); } private void register_Click_1(object sender, EventArgs e) { Form8 f8 = new Form8(); if ((textBox4.Text != "") && (textBox1.Text != "") && (textBox2.Text != "") && (textBox3.Text != "")) { if (IsValidEmail(textBox4.Text)) { message = new MailMessage(); message.To.Add(textBox4.Text); message.CC.Add(textBox4.Text); message.Subject = "pin"; message.From = new MailAddress("[email protected]"); message.Body = "thank you for loging in to greeting card editor application.this is the pin you should enter for validation 0001"; smtp = new SmtpClient("smtp.gmail.com",587); smtp.EnableSsl = true; smtp.Timeout = 5000; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential("[email protected]", "sisicricri...14"); smtp.SendAsync(message, message.Subject); smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted); f8.Show(); this.Close(); } else if (!IsValidEmail(textBox4.Text)) MessageBox.Show(textBox4.Text + " is not in a valid email format.", "Invalid Email", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else MessageBox.Show("you should fill all the informations before you click register button!!"); } }}推荐答案 这篇关于确保我的代码正确:从winform应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-07 06:18