Click to See Complete Forum and Search --> : Retrieve Sender Address from EMail. (Outlook 2003).


sotoasty
September 25th, 2008, 06:01 AM
So, here is my code. What I would like to do, is retrieve the EMail address from the sender so I can send an SMTP EMail based on some rules I set up. This is for a Automation EMail address, that catches EMail for several accounts. Please don't be brutal on my code, I am new to c# and just trying to get this mini project done.


foreach (_MailItem objMail in MainFolder.Items)
{
clsEMail MI = new clsEMail();
MI.PossibleSpam = false;
if (objMail.BodyFormat == OlBodyFormat.olFormatPlain)
{
MI.Body = objMail.Body;
MI.MailData = objMail.Body;
MI.ProbableType = "T";
}
else
{
MI.Body = objMail.HTMLBody;
MI.MailData = objMail.Body;
MI.ProbableType = "H";
}
MI.Sender = objMail.SenderName;
MI.Subject = objMail.Subject;
_MailItem RR = objMail.Reply();
RR.Body = "This.....";
RR.Subject = "Receipt for " + MI.Subject;

// HERE IS WHERE I Tried to get the address
//foreach (Recipient CC in RR.ReplyRecipients)
//{
// MI.SenderAddress = CC..Address;
// break;
//}

RR.Send();
RR = null;
if (objMail.Attachments.Count >= 1)
{
foreach (Attachment BB in objMail.Attachments)
{
clsAttachment CC = new clsAttachment();
CC.Doc = BB;
MI.Attachments.Add(CC);
CC = null;
}
}
MI.Save();
if (!MI.IsError)
{
objMail.Delete();
}
if (MI.IsError)
{
OnEmailReceived(MI.Subject, "Failed", "", "");
}
else
{
OnEmailReceived(MI.Subject, "Successful", MI.Sender, MI.Sender);
}
MI.CleanUp();
MI = null;
}
MainFolder = null;
}
catch (System.Exception e)
{
OnFailure("Unable to Access Mail. " + e.Message);
}
}



As it stands now, I am having to reply through outlook and I get delay on the processing.

Any help on this would be appreciated.