Hi. Please help, i am trying to program a simple email application for my window pc using c#. I keep getting "NullReferenceException was unhandled" at line 37 when i debug.

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using Microsoft.WindowsMobile.PocketOutlook;
using System.Web.Services;

namespace SmartDeviceProject1
{
    public partial class Form1 : Form
    {
        OutlookSession aSession;
        public Form1()
        {
            InitializeComponent();
            aSession = new OutlookSession();
        }

        private void btnAlert_Click(object sender, EventArgs e)
        {
            EmailAccount myAcct = aSession.EmailAccounts["POP3"];
           
            EmailMessage mesg = new EmailMessage();

            mesg.BodyText = "Hello.";

            Recipient recv = new Recipient("xxx", "xxx@hotmail.com");

            mesg.To.Add(recv);

            myAcct.Send(mesg);

            MessageBox.Show("Done!", "Notice");

            this.btnAlert.Enabled = false;
           
        }
    }
}

Are you sure myAcct is not null at this point?
When your app breaks because of the error, hover over myAcct with your mouse.
A tool tip will pop up with its current value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.