为什么邮件不会发送到我的Outlook邮件?

时间:2013-12-19 15:15:16

标签: c# asp.net

我正在创建一个网站供用户填写信息。完成填写信息后,用户单击按钮提交票证并作为副本向我发送电子邮件。但是,我点击发送后没有收到任何电子邮件。除了电子邮件,提交票证成功。我们使用Microsoft Outlook。 任何人都知道为什么或我错过了什么?

我添加了引用using Outlook = Microsoft.Office.Interop.Outlook;

C#代码,

protected void BtnIPAM_Click(object sender, EventArgs e)
{
    //codes for submitting ticket then send email

    string uid = Bam.NEAt.GetUserID();

    try
    {
        //Create the Outlook application
        Outlook.Application oApp = new Outlook.Application();
        //Create the new message
        Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
        //Add a recipient
        Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("xxxxx@xxxx.com");

        oRecip.Resolve();

        //Set the basic properties
        oMsg.Subject = "A Copy of IP Address Request";
        oMsg.Body = "This is a test who sent by " + uid;

        //Send the message
        oMsg.Save();
        oMsg.Send();

        oRecip = null;
        oMsg = null;
        oApp = null;

    }
    catch {}
}

1 个答案:

答案 0 :(得分:3)

用它来发送电子邮件:

    using System.Net;
    public static void SendAlertEmail()
    {
       System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
       message.To.Add("receive@whatever.com");
       message.Subject = "Put Subject";
       message.From = new System.Net.Mail.MailAddress("sender@whatever.com");
       message.Body = "Body Message Here";
       System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
       smtp.Host = "put host settings here";
       smtp.Port = 25;
       smtp.EnableSsl = false;
       smtp.Send(message);
    }

要打电话给它:

SendAlertEmail();