Click here to Skip to main content
11,502,201 members (66,105 online)

avmvijay asked:

Open original thread
Hi,

We have web application, two persons send email at same time but second person body content goes to first person. its only for same time and seconds.

server SMTP and mailmessage used to send.

How to fix this issue?

Code:

public override string SendReplyMail_To_Client(string TICKETNUMBER, string REPLYMESSAGE, int TemplateNumber, int Portal_Id, int Module_Id, string FromEmail, string ToEmail, string Att, string Added_CC, string subject, out string Error, out string ReplyError)
{
Error = "";
ReplyError = "";
if (ToEmail != "" && FromEmail != "")
{
// Added on 20th March 2009
FromEmail = Get_From_Email_Address(FromEmail, TICKETNUMBER, Portal_Id, Module_Id);

ds_ticket = new DataSet();
try
{
ds_ticket = DataProvider.Instance().Get_Ticket_Details_By_Ticket_Number_For_Email_Template(TICKETNUMBER);
}
catch (Exception ex)
{
insert_Log("====>> Error in Get_Ticket_Details_By_Ticket_Number_For_Email_Template: " + ex.Message + " Time : " + DateTime.Now.ToLongTimeString());
}

if (ds_ticket != null)
{

ds_reply_mail = new DataSet();
SqlParam = new SqlParameter[]
{
new SqlParameter("@TemplateNumber",TemplateNumber),
new SqlParameter("@Ticket_Number",TICKETNUMBER),
new SqlParameter("@Portal_Id",Portal_Id),
new SqlParameter("@Module_Id",Module_Id)
};

try
{
ds_reply_mail = DataProvider.Instance().Get_EmailTemplates_By_TemplateNumber(SqlParam);
insert_Log("====>> Reply template Ticket_Number is-: " + TICKETNUMBER);
}
catch (Exception ex)
{
insert_Log("====>> Error in Get_EmailTemplates_By_TemplateNumber: " + ex.Message + " Time : " + DateTime.Now.ToLongTimeString());
}

insert_Log("====>> Reply FromEmail is-: " + FromEmail);
insert_Log("====>> Reply ToEmail is-: " + ToEmail);
insert_Log("====>> Reply CCEmail is-: " + Added_CC);

if (ds_reply_mail.Tables[0].Rows.Count > 0)
{
// From Email Template.....
EmailSubject = ds_reply_mail.Tables[0].Rows[0]["EmailSubject"].ToString().Trim();
EmailText = DataProvider.Instance().Get_String((Byte[])ds_reply_mail.Tables[0].Rows[0]["EmailText"]);


if (EmailText.Contains("||"))
{
EmailText = EmailText.Replace("||", "'");
}



// Email Text Replacement
for (int ColumnIndex = 0; ColumnIndex < ds_ticket.Tables[0].Columns.Count; ColumnIndex++)
{
if (EmailText.Contains(ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim()))
{
if (ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim() != "#REQUESTDESC#")
{
EmailText = EmailText.Replace(ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim(), ds_ticket.Tables[0].Rows[0][ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim()].ToString().Trim());
//EmailSubject = EmailSubject.Replace(ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim(), ds_ticket.Tables[0].Rows[0][ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim()].ToString().Trim());
}
else
{
EmailText = EmailText.Replace(ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim(), DataProvider.Instance().Get_String((Byte[])ds_ticket.Tables[0].Rows[0][ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim()]));
// EmailSubject = EmailSubject.Replace(ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim(), ds_ticket.Tables[0].Rows[0][ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim()].ToString().Trim());
}
}
}

// Email Subject Replacement
for (int ColumnIndex = 0; ColumnIndex < ds_ticket.Tables[0].Columns.Count; ColumnIndex++)
{
if (EmailSubject.Contains(ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim()))
{
if (ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim() != "#REQUESTDESC#")
{
EmailSubject = EmailSubject.Replace(ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim(), ds_ticket.Tables[0].Rows[0][ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim()].ToString().Trim());
}
else
{
EmailSubject = EmailSubject.Replace(ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim(), ds_ticket.Tables[0].Rows[0][ds_ticket.Tables[0].Columns[ColumnIndex].ColumnName.Trim()].ToString().Trim());
}
}
}


if (EmailText.Contains("#REPLYMESSAGE#"))
{
EmailText = "" + EmailText.Replace("#REPLYMESSAGE#", REPLYMESSAGE) + "";//EmailText.Replace("#REPLYMESSAGE#", REPLYMESSAGE);
}


MailMessage Mail = new MailMessage();
Mail.From = FromEmail;
// added by saravanan
bool success;
success = _imap.UnlockComponent("SInterProBPSIMAPMAIL_X1BXirBD7ZA8");
if (success != true)
{
Error = _imap.LastErrorText;
insert_Log("====>>Error in _imap.UnlockComponent Reply Mail send " + _imap.LastErrorText);
// MessageBox.Show(_imap.LastErrorText);
//return;
}
success = _imap.Connect(Get_SMTP_Host_Server_Name().ToString());
if (success != true)
{
Error = _imap.LastErrorText;
insert_Log("====>>Error in _imap.Connect Reply Mail send " + _imap.LastErrorText);
//MessageBox.Show(_imap.LastErrorText);
//return;
}

string password;

strSql = "select distinct CRM_Email_Password from CCQMP_Rep_Mapping where CRM_Email_Address= '" + FromEmail + "' and Status='A'";
password = DataProvider.Instance().ExecuteScalar(strSql);
success = _imap.Login(FromEmail, password);
if (success != true)
{
Error = _imap.LastErrorText;
insert_Log("====>>Error in _imap.Login Reply Mail send " + _imap.LastErrorText);
//MessageBox.Show(_imap.LastErrorText);
// return;
}

Chilkat.Email _email = new Chilkat.Email();

// added by saravanan
cc = "";

try
{
if (ToEmail.Contains(";"))
{
string[] strarray = ToEmail.Split(';');
if (strarray.Length > 0)
{
Email = "";
for (int i = 0; i < strarray.Length; i++)
{
if (DataProvider.Instance().Is_CRM_Email(strarray[i].ToString(), Portal_Id, Module_Id).Trim() == "No")
{
Email += strarray[i].ToString() + ";";
}
}
}
else
{
Email = string.Empty;
}
cc = Email;

}
else
{
cc = ToEmail;
}

}
catch (Exception ex)
{
insert_Log("====>> Error in Reply send mail CC problem: " + ex.Message + " Time : " + DateTime.Now.ToLongTimeString());
cc = "";
}

Mail.To = cc;

cc = "";
Email = "";
try
{
if (Added_CC.Contains(";"))
{
string[] strarray = Added_CC.Split(';');
if (strarray.Length > 0)
{
Email = "";
for (int i = 0; i < strarray.Length; i++)
{
if (DataProvider.Instance().Is_CRM_Email(strarray[i].ToString(), Portal_Id, Module_Id).Trim() == "No")
{
Email += strarray[i].ToString() + ";";
}
}
}
else
{
Email = string.Empty;
}
cc = Email;

}
else
{
cc = Added_CC;
}

}
catch (Exception ex)
{
insert_Log("====>> Error in Reply send mail CC problem -1: " + ex.Message + " Time : " + DateTime.Now.ToLongTimeString());
cc = "";
}


if (cc.Length > 0)
{
//Mail.Cc = cc;
Mail.Cc = cc;
_email.AddCC("", cc);
}

//// Added on 16th jan 2009

//if (!Mail.To.Contains("@"))
//{
// if (Mail.Cc.Contains("@"))
// {
// Mail.To = Mail.Cc;
// }
//}
//// End on 16th jan 2009
if (subject != null && subject != "")
Mail.Subject = subject;
else
Mail.Subject = EmailSubject;
Mail.BodyFormat = MailFormat.Html;

if (Att.Length > 0)
{
if (Att.Trim() != "")
{
if (Att.Contains(","))
{
strArray = Att.Split(Convert.ToChar(","));
if (strArray.Length > 0)
{

for (int Att_Index = 0; Att_Index < strArray.Length; Att_Index++)
{
if (strArray[Att_Index].ToString().Trim() != "")
{
// Attach the newly created email attachment
MailAttachment attach = new MailAttachment(strArray[Att_Index].ToString());
Mail.Attachments.Add(attach);
_email.AddFileAttachment(strArray[Att_Index].ToString());
}
}
}
}
}
}





Mail.Body = EmailText;
try
{

Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Get_SMTP_Host_Username());
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Get_SMTP_Host_Password());

// ds = new DataSet();
// ds = DataProvider.Instance().Get_Server_Config_Details();

SmtpMail.SmtpServer = Get_SMTP_Host_Server_Name();


if (DataProvider.Instance().Is_CRM_Email(ToEmail, Portal_Id, Module_Id).Trim() == "No")
{
_email.SetHtmlBody(Mail.Body);
_email.Subject = subject;
_email.AddTo(ToEmail, ToEmail);
_email.From = FromEmail;
try
{

SmtpMail.Send(Mail);
success = _imap.AppendMail("Sent Items", _email);
insert_Log("====>> Reply Mail send Successfully ");
if (success != true)
{
Error = _imap.LastErrorText;
insert_Log("====>>Error in _imap.AppendMail Reply Mail send " + _imap.LastErrorText);
//MessageBox.Show(_imap.LastErrorText);
// return;
}
}
catch (Exception ex)
{
//Start To Mail
string[] ToEmalId = ToEmail.Split(';');
System.Collections.Generic.List list = new System.Collections.Generic.List();
foreach (string strID in ToEmalId)
{
string[] straID = strID.Split(',');
foreach (string str in straID)
{
list.Add(str);
}
}
foreach (string toid in list)
{
if (toid != "")
{
if (ex.Message.Contains(toid))
{

//Mail.To = Mail.To.Replace(toid, string.Empty);
ReplyError = "The Email id " + toid + " is Invalid.Please correct and resend again";
}
}
}
//End To Mail

//Start CC Mail
string[] CCEmalId = Added_CC.Split(';');
System.Collections.Generic.List list1 = new System.Collections.Generic.List();
foreach (string strID in CCEmalId)
{
string[] straID1 = strID.Split(',');
foreach (string str in straID1)
{
list1.Add(str);
}
}
foreach (string CCid in list1)
{
if (CCid != "")
{
if (ex.Message.Contains(CCid))
{
//Mail.Cc = Mail.Cc.Replace(CCid, string.Empty);
ReplyError = "The Email id " + CCid + " is Invalid.Please correct and resend again";
}
}

}
//End CC Mail

insert_Log("====>>Error in catch block reply mail to client: " + ex.Message);
}
//textBox1.Text += "Email uploaded to Inbox!" + "\r\n";

//// Disconnect from the IMAP server.
_email.Dispose();
_imap.Disconnect();


/// Testing a mail append in the send item in the crm email
/// Created by saravanan
/// Created On : 18-MAY-2011
/// Using Chilkat .NET

//bool success;
//success = _imap.UnlockComponent("SInterProBPSIMAPMAIL_X1BXirBD7ZA8");
//if (success != true)
//{
// MessageBox.Show(_imap.LastErrorText);
// //return;
//}
//success = _imap.Connect(Get_SMTP_Host_Server_Name().ToString());
//if (success != true)
//{
// MessageBox.Show(_imap.LastErrorText);
// //return;
//}

//string password;

//strSql = "select distinct CRM_Email_Password from CCQMP_Rep_Mapping where CRM_Email_Address= '"+FromEmail+"' and Status='A'";
//password = DataProvider.Instance().ExecuteScalar(strSql);
//success = _imap.Login(FromEmail, password);
//if (success != true)
//{
// MessageBox.Show(_imap.LastErrorText);
//// return;
//}

//Chilkat.Email _email = new Chilkat.Email();

//_email.SetHtmlBody (Mail.Body);
//_email.Subject = EmailSubject;
//_email.AddTo(ToEmail, ToEmail);
//_email.From = FromEmail;


//if (Att.Length > 0)
//{
// if (Att.Trim() != "")
// {
// if (Att.Contains(","))
// {
// strArray = Att.Split(Convert.ToChar(","));
// if (strArray.Length > 0)
// {

// for (int Att_Index = 0; Att_Index < strArray.Length; Att_Index++)
// {
// if (strArray[Att_Index].ToString().Trim() != "")
// {
// _email.AddFileAttachment(strArray[Att_Index].ToString());
// }
// }
// }
// }
// }
//}

//if (cc.Length > 0)
//{
// //Mail.Cc = cc;
// _email.AddCC("", cc);
//}
//success = _imap.AppendMail("Sent Items",_email );

//if (success != true)
//{
// MessageBox.Show(_imap.LastErrorText);
//// return;
//}

////textBox1.Text += "Email uploaded to Inbox!" + "\r\n";

////// Disconnect from the IMAP server.
//_imap.Disconnect();



/// Ended Here Testing a mail append in the send item in the crm email


}
}
catch (Exception ex)
{
insert_Log("====>> Error Message from class: " + ex.Message + " Time : " + DateTime.Now.ToLongTimeString());
//retVal = "Error Message from class: " + e1.Message;
}

}

}
}

return retVal;
}
Tags: C#

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100