0

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;
           
        }
    }
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by nick.crane
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.