0

I am creating a website for user to fill out information. After completed fill out information, the user click button to submit a ticket and send email to me as a copy. However, I didn't receive any email after I click to send it. The submit ticket was successful except the email. We use Microsoft Outlook. Anyone know why or I am missing something?

I did add the reference using Outlook = Microsoft.Office.Interop.Outlook;

C# codes,

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 {}
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
StudentIT
  • 481
  • 2
  • 19
  • 45

1 Answers1

3

use this to send an email:

    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);
    }

To call it use this:

SendAlertEmail();
Joe
  • 7,113
  • 1
  • 29
  • 34
SlopTonio
  • 1,105
  • 1
  • 16
  • 39