Can't send mail from Outlook via C#
I'm trying to send mails to my co workers, but after the 1st mail, the
application crashes. I get this message
COMException was unhandled by user code. "The item has been moved or
deleted."
private void SendMail()
{
var usersEmailAddresses = Factory.Users.List(); // .List() lists all
the data from the Users table.
Application OutlookApplication = new Application();
MailItem OutlookMail =
(MailItem)OutlookApplication.CreateItem(OlItemType.olMailItem);
OutlookMail.Subject = @"TEST/Ushqimi i caktuar per sot";
MailBody //region, here I assign the MailBody Text.
for (int index = 0; index < usersEmailAddresses.Count; index++)
{
OutlookMail.To = usersEmailAddresses[index].Email; //Here is
where I get the exception, AFTER trying to assign the second
email.
if (usersEmailAddresses[index].RecieveEmail &&
!usersEmailAddresses[index].IsOnVacation)
{
((_MailItem)OutlookMail).Send();
}
}
}
What Am I doing wrong? Any suggestions?
No comments:
Post a Comment