不能通过Hotmail发送电子邮件,只能通过Gmail

本文关键字:Gmail Hotmail 不能 电子邮件 | 更新日期: 2023-09-27 18:16:19

我有一个问题。我编写了一个程序,可以让你从。txt列表中向这个地址发送电子邮件。它有效(我在德国),但对其他人(在其他国家)不起作用。对他们来说,只有通过Gmail发送电子邮件才管用。任何帮助吗?

代码如下:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private void cmdDistribute_Click(object sender, EventArgs e)
    {
        FileStream fs;
        StreamReader sr;
        if (Receiverlist.Text == "")
        {
            MessageBox.Show("Please type in the path of the list with the receiver! (.txt)", "ERROR : CANT FIND RECEIVERLIST!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }
        fs = new FileStream(Receiverlist.Text, FileMode.Open);
        sr = new StreamReader(fs);
        string zeile;
        if (senderID.Text == "")
        {
            MessageBox.Show("Please type in your login information!", "ERROR : NO EMAIL ADDRESS!");
            fs.Close();
            return;
        }
        else if (SenderPassword.Text == "")
        {
            MessageBox.Show("Please type in your login information!", "ERROR : NO PASSWORD!");
            fs.Close();
            return;
        }
        MessageBox.Show("While sending the emails this programm won´t  response till it has send 'nall emails! This could take a while, so please be patient...", "ALERT", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        string mailProvider = "";
        int port = 0;
        try
        {
            if (ProviderGmail.Checked)
            {
                mailProvider = "smtp.gmail.com";
                port = 587;
            }
            else if (providerHotmail.Checked)
            {
                mailProvider = "smtp.live.com";
                port = 587;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Can´t connect to the GMail / Hotmail server. 'n Please contact TheFlash on skype!", "ERROR : SMTPSERVER", MessageBoxButtons.OK, MessageBoxIcon.Error);
            fs.Close();
            return;
        }
        if (EmailSubject.Text == "")
        {
            MessageBox.Show("Please type in the subject of the email!.", "ERROR : EMPTY SUBJECT", MessageBoxButtons.OK, MessageBoxIcon.Error);
            fs.Close();
            return;
        }
        int n = 1;
        while (sr.Peek() != -1)
        {
            zeile = sr.ReadLine();
            try
            {
                System.Net.Mail.MailAddress DistributorMail = new System.Net.Mail.MailAddress(senderID.Text);
                System.Net.Mail.MailAddress Receiver = new System.Net.Mail.MailAddress(zeile);
                System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage(DistributorMail, Receiver);
                email.Subject = EmailSubject.Text;
                email.Body = EmailBody.Text;
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(mailProvider,port);
                client.EnableSsl = true;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(senderID.Text, SenderPassword.Text);
                if (checkBox1.Checked)
                {
                    if (EmailAttachment.Text == "")
                    {
                        MessageBox.Show("Please type in the path of your attachment!.", "ERROR : EMPTY ATTACHMENT PATH", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        fs.Close();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("If you add an attachment to your mail, it will take longer to send it!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        email.Attachments.Add(new System.Net.Mail.Attachment(EmailAttachment.Text));
                    }
                }
                else
                {
                    EmailAttachment.Enabled = false;
                }
                try
                {
                    client.Send(email);
                    label9.Text = "Emails sent : " + n;
                    n = n + 1;
                    if (sr.Peek() == -1)
                        MessageBox.Show("Finished!", "TheFlash´s Email Distributor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception Ex)
                {
                    label9.Text = "Couldn´t send the emails!";
                    fs.Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("This is not an valid email address.", "ERROR : WRONG EMAIL FORMAT", MessageBoxButtons.OK, MessageBoxIcon.Error);
                fs.Close();
                return;
            }
        }
        fs.Close();
        return;
    }
    private void cmdExit_Click(object sender, EventArgs e)
    {
        Close();
    }
    private void cmdAbout_Click(object sender, EventArgs e)
    {
        new AboutBox1().Show();
    }
}

不能通过Hotmail发送电子邮件,只能通过Gmail

好吧,由于这样或那样的原因,看起来你的用户可能已经被锁定了他们的Hotmail帐户。所以他们可以尝试通过正常的网页登录,看看他们是否被要求解决一个谜题来解锁它。有关这方面的更多信息,请参阅:

为什么我的Hotmail帐户总是被锁住,我该怎么做?

我不确定是否可以围绕此进行编码。你可以在这里查看过去的问题:

SMTP Client发送错误

通过Hotmail发送邮件到gmail

也看到:

通过Hotmail/Outlook/Windows Live从c#发送电子邮件

在c#中使用smtp.live.com发送邮件时遇到的问题