0 votes
by (750 points)

Hello Rebex Team,
I used the trial version of Rebex secure mail where I created a small console application which processes mail from my mailling server for an account.It processes each mail from the inbox one at a time and its respective attachments.Everything is getting processed properly no problem at all but the real problem arises when I have 50 emails in the inbox with different attachments it takes almost 15 minutes to process everything which is very time consuming. Can we get anything so that the processing becomes much faster. Any help will be appreciated as soon as possible.
Below is the code of my application for your reference.

static void Main(string[] args)
{
string GroupID = "";
if (args.Length != 0)
{
GroupID = args[0];
}
else
{
GroupID = "";
}
List objGenericInvoicesImport = Comman.GetGenericConfiguration(GroupID);
string strTemp = "D:\RahulTemp\";
Rebex.Licensing.Key = "==Asw8ngRi512lyhFyNlbzu11kO9zWdXn+xvPOqHEeNwTA==";
//Rebex.Licensing.Key = "==AIP+enF11Sz9P6dho42Ws6LOsVlMTUYEn5RI3fJqNxzI==";
SslMode _security = SslMode.Implicit;
for (int j = 0; j < objGenericInvoicesImport.Count; j++)
{
Imap imap = new Imap();
imap.LogWriter = new Rebex.FileLogWriter(@"D:\Rahultemp\log.txt", Rebex.LogLevel.Error);
imap.Connect("mail.iqbackoffice.com", 993, _security);
imap.Login(objGenericInvoicesImport[j].EmailID, "Temp123");
imap.SelectFolder("TempTry");
imap.Timeout = int.MaxValue;
ImapMessageCollection lst = imap.Search(ImapSearchParameter.Not(ImapSearchParameter.Deleted));
foreach(var val in lst)
{
Regex regex = new Regex("[\~#%&*{}/:<>?|\"-]");
MailMessage mm = new MailMessage();
mm = imap.GetMailMessage(val.UniqueId);
MailMessage mm2 = new MailMessage();
foreach (Attachment attachment in mm.Attachments)
{
if (attachment.FileName.ToLower().EndsWith(".pdf") || attachment.FileName.ToLower().EndsWith(".docx") || attachment.FileName.ToLower().EndsWith("xls") || attachment.FileName.ToLower().EndsWith("xlsx") || attachment.FileName.ToLower().EndsWith("doc"))
{
if (regex.IsMatch(attachment.FileName.ToLower()))
{
string mt = attachment.MediaType;
if (mt == "application/pdf")
{
attachment.Save(strTemp + "NameRenamed" + ".pdf");
mm2.Attachments.Add(new Attachment(strTemp + "NameRenamed" + ".pdf"));
}
else if (mt == "application/vnd.ms-excel")
{
attachment.Save(strTemp + "NameRenamed" + ".xls");
mm2.Attachments.Add(new Attachment(strTemp + "NameRenamed" + ".xls"));
}
else if (mt == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
attachment.Save(strTemp + "NameRenamed" + ".xlsx");
mm2.Attachments.Add(new Attachment(strTemp + "NameRenamed" + ".xlsx"));
}
else if (mt == "application/msword")
{
attachment.Save(strTemp + "NameRenamed" + ".doc");
mm2.Attachments.Add(new Attachment(strTemp + "NameRenamed" + ".doc"));
}
else if (mt == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
{
attachment.Save(strTemp + "NameRenamed" + ".docx");
mm2.Attachments.Add(new Attachment(strTemp + "NameRenamed" + ".docx"));
}
}
else
{
attachment.Save(strTemp + attachment.FileName);
mm2.Attachments.Add(new Attachment(strTemp + attachment.FileName));
}
}
else
{
string mt = attachment.MediaType;
if (mt == "application/pdf")
{
attachment.Save(strTemp + attachment.FileName + ".pdf");
mm2.Attachments.Add(new Attachment(strTemp + attachment.FileName + ".pdf"));
}
else
{
attachment.Save(strTemp + attachment.FileName);
mm2.Attachments.Add(new Attachment(strTemp + attachment.FileName));
}
}
}
Smtp objsmtp = new Smtp();
objsmtp.Connect(ConfigurationManager.AppSettings["SmptServerName"].ToString(), 25);
//objsmtp.Login(ConfigurationManager.AppSettings["SmtpUserName"].ToString(), ConfigurationManager.AppSettings["SmtpPassword"].ToString());
mm2.From = "noreply@iqbackoffice.com";
mm2.To = "rahulacc13@gmail.com";
mm2.CC = "ajay.vishwakarma@infinxinc.com";
mm2.BodyText = "hello";
objsmtp.Send(mm2);
imap.CopyMessage(val.UniqueId, "Archive");
imap.DeleteMessage(val.UniqueId);
}
imap = null;
}
}

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (58.9k points)

Hello rockyshah2015,

please change your program to also log the LogLevel.Debug information for both Imap and Smtp client instances like this:

Imap imap = new Imap();
imap.LogWriter = new Rebex.FileLogWriter(@"D:\Rahultemp\logRebex.txt", Rebex.LogLevel.Debug);

...

Smtp objsmtp = new Smtp();
objsmtp.LogWriter = new Rebex.FileLogWriter(@"D:\Rahultemp\logRebex.txt", Rebex.LogLevel.Debug);

I also recommend you to discard this line of code:

imap.Timeout = int.MaxValue;

Please send us the newly created log - you can post it here as an answer to this question, or send it to support@rebex.net

Based on this we will check why it takes your program so long to execute with your servers and let you know then.

Thanks!

by (58.9k points)
Thank you for sending the log file via emai!

According to the log file the most time consuming operation is actually the imap.GetMailMessage.

I have analyzed the log and fetching each one of the 312kb emails takes 8 seconds with your IMAP server on average:

2015-03-17 01:17:47.921 INFO Imap(2)[9] Response: * 254 FETCH (BODY[] {455110}
2015-03-17 01:17:54.547 INFO Imap(2)[9] Response: ...455110 bytes...
2015-03-17 01:17:54.547 INFO Imap(2)[9] Response: )
2015-03-17 01:17:54.547 INFO Imap(2)[9] Response: R00007 OK FETCH completed

I have tested Rebex IMAP client both with Gmail IMAP server and with our Exchange IMAP server and I was able to get much higher speeds when performing the same task:

to download a sample email with an attachment of size 338KB 50 times from the
-    Gmail imap server -  it took me 58 seconds
-    Exchange server – it took only 3 seconds (the Exchange is on our LAN network, so there is much higher speed).

So I am afraid the bottle neck for you is either the server that you are connecting to, or the slow network along the way, but the slowdown does not seem to be caused by Rebex IMAP client.
...