这是我尝试过的代码:
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.Web;
using System.Net.Mail;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Send_Click(object sender, EventArgs e)
{
MailMessage reece = new MailMessage("FromEmail", "ToEmail", "Hello", "How are you");
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential("MyEmail", "MyPassword");
smtp.Port = 465;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.Send(reece);
MessageBox.Show("Sent");
}
}
}
我一直在超时。尝试了很多不同的端口组合。
答案 0 :(得分:1)
您尝试连接的服务器需要启用SSL。
smtp.EnableSsl = true;
同时将端口更改为995
或465
。
更多信息:https://portal.smartertools.com/kb/a2862/smtp-settings-for-outlook365-and-gmail.aspx