好的; 我似乎无法发送邮件消息。我将其作为控制台应用程序运行:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace Email
{
class Program
{
static void EMail(string ToAddress, string Subject, string Body, string FromAddress, string Host, int Port, string Username, string Password)
{
System.Net.Mail.SmtpClient SMTPClient = new System.Net.Mail.SmtpClient(Host, Port);
System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
Message.To.Add(new System.Net.Mail.MailAddress(ToAddress));
Message.From = new System.Net.Mail.MailAddress(FromAddress);
Message.Body = Body;
Message.Subject = Subject;
SMTPClient.EnableSsl = true;
SMTPClient.Credentials = new System.Net.NetworkCredential(Username, Password);
SMTPClient.Send(Message);
SMTPClient.SendCompleted += new System.Net.Mail.SendCompletedEventHandler(FinishedSending);
}
static void FinishedSending(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
Console.WriteLine("DONE!");
}
static void Main(string[] args)
{
EMail("***********", "Hi!", "This is a test, Sent from a C# application.", "******", "smtp.gmail.com", 465, "****************", "**************");
Console.ReadLine();
}
}
}
我没有收到任何错误,我没有在我的 gmail 帐户中收到它,也没有写“完成!”。我已经允许端口 465,传出和传入。在端口 465 上远程登录 smtp.gmail.com 会导致一个空白的命令提示符窗口。谢谢。