因此,我想尝试使用 Visual C# 应用程序向自己发送一些邮件,但它似乎只是通过代码运行(我知道这一点,因为我在代码末尾放置了一个消息框)并且不发送任何内容。出于明显的原因,我确实更改了下面的电子邮件信息。
这是我所拥有的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string Host = "smtp.live.com";
Int16 Port = 587;
bool SSL = true;
string Username = "myemail@hotmail.com";
string Password = "mypassword";
// Mail options
string To = "myemail@hotmail.com";
string From = "email@hotmail.com";
string Subject = "This is a test";
string Body = "It works!";
MailMessage mm = new MailMessage(From, To, Subject, Body);
SmtpClient sc = new SmtpClient(Host, Port);
NetworkCredential netCred = new NetworkCredential(Username, Password);
sc.EnableSsl = SSL;
sc.UseDefaultCredentials = false;
sc.Credentials = netCred;
MessageBox.Show("Test");
}
}
}
*注意,我没有得到任何错误。