是否有更有效的邮件发送方式?

时间:2013-09-06 01:21:54

标签: c# performance time gmail

我的主要目的是简单地用附件发送邮件给自己。

目前,我使用的是smtp客户端,但需要约5分钟,而且非常不可靠。

这是我目前的代码:

    private SmtpClient smtp;
    private void button2_Click(object sender, EventArgs e)
    {
        if (smtp != null)
            return;
        string username = "", password = "";
        if (checkBox2.Checked)
            username = textBox7.Text;
        if (checkBox3.Checked)
            password = textBox8.Text;
        if (username != "" || password != "")
        {
            //save info
        }
        label17.Text = "In Progress...";
        MailAddress me = new MailAddress(textBox7.Text, "Me");
        smtp = new SmtpClient("smtp.gmail.com", 465);
        smtp.Timeout = 300000;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = new System.Net.NetworkCredential(me.Address, textBox8.Text);
        MailMessage message = new MailMessage(me, me);
        message.Subject = page.ActiveDocument.Name;
        message.Body = "r u mad tho?";
        string path = "path to file";
        message.Attachments.Add(new Attachment(path));
        smtp.SendCompleted += Completed;
        smtp.SendAsync(message, label17.Text);
    }
    private void Completed(object sender, EventArgs e)
    {
        label17.Text = "Done!";
        smtp.Dispose();
        smtp = null;
    }

字符串路径值可以忽略不计;我知道这是正确的路径,用户名/密码也是如此。

0 个答案:

没有答案