EDN Admin
Well-known member
Hi All,
We have a C# code that is being called by SAP using RFC. SAP sends the subject, recepient and body of the e-mail. The body of the e-mail is received in a SAPTable format.
The SAP RFC calls a function written in C# on a windows server. This function takes all the parameters and creates an Outlook.MailItem object. Then this object is moved to the Sent Items folder of Outlook and then sent to the designated recepient.
Now, this program has started failing and is not able to send the required e-mails.
SAP is able to make the RFC and send the e-mail text etc. to the C# code, but the code is not able to send mail via Outlook. Following error message is generated:
"System.Runtime.InteropServices.COMException (0xC1F40102): Could not complete the operation because the service provider does not support it."
Could you please help me resolve this?
I brief idea of the code steps is as follows:
<span style="text-decoration:underline <span style="text-decoration:underline RFC function
protected override void Z_Rfc_Send_Mail (<br/>
string P_Buttons,string P_Order,string P_Subject,string P_To,ref TLINETable P_Table)<br/>
{<br/>
StringBuilder bodyHTMLText;<br/>
string sentTo = P_To;<br/>
<br/>
bodyHTMLText = new StringBuilder();<br/>
for (int i = 0; i < P_Table.Count; i++)<br/>
{<br/>
bodyHTMLText.Append(P_Table.Tdline);<br/>
}<br/>
try<br/>
{<br/>
OutlookMethod olMail = new OutlookMethod();<br/>
olMail.Outlook_SendMail(P_Buttons,P_Order,P_Subject,P_To,bodyHTMLText.ToString());<br/>
olMail = null;<br/>
}
:
:
} //end of RFC function
<span style="text-decoration:underline Outlook_SendMail method
Outlook.Application olApp; <br/>
Outlook.NameSpace olNS;<br/>
Outlook.MAPIFolder mailBox;<br/>
Outlook.MailItem olMail;
try <br/>
{<br/>
olApp = new Outlook.Application(); <br/>
olNS = olApp.GetNamespace("MAPI");<br/>
xx_mailBox = FindMailFolder(olNS.Folders, ConfigurationSettings.AppSettings["*******.Name"]) as Outlook.MAPIFolder;<br/>
<br/>
Outlook.MAPIFolder c_SentBox = FindMailFolder(xx_mailBox.Folders, "Sent Items") as Outlook.MAPIFolder;<br/>
olMail = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);<br/>
if (ConfigurationSettings.AppSettings["testTo"] == null)<br/>
{<br/>
olMail.Recipients.Add(P_To);<br/>
}<br/>
else<br/>
{<br/>
sentTo = ConfigurationSettings.AppSettings["testTo"];<br/>
olMail.Recipients.Add(sentTo);
}
//----------------------- email subject<br/>
olMail.Subject = P_Subject + " # " + P_Order;<br/>
//----------------------- HTML body
olMail.HTMLBody = bodyHTMLText;<br/>
LogFile("step 11 : bodyHTMLText is"+bodyHTMLText);
//---------------------- move the email to Sent Items folder for archives purpose<br/>
olMail.Move(c_SentBox);
olMail.Send();<br/>
//---------------------<br/>
olMail=null;<br/>
olNS = null;<br/>
olApp= null;
//Garbage Collection<br/>
GC.Collect();
--------------------------
We tried to hardcode the values for subject, order#, recepient, html body in the outlook.send_mail method and called this method directly (instead of calling it in the Z_RFC_Send_Mail function) This way the e-mail was generated successfully.
But when we it is called from the RFC/Z_RFC_Send_Mail function, then the above error message is encountered. We added some log points in the code and know that the Z_RFC_Send_Mail is able to call the Outlook.Send_Mail but within Outlook.Send_Mail the exception
is being thrown.
Sometimes, we also encounter the error message "Server Execution Failed". This usually comes at the beginning of the Try block in Outlook.Send_Mail method.
Itll be great if some one can help us resolve this issue.
Thanks for your time!
View the full article
We have a C# code that is being called by SAP using RFC. SAP sends the subject, recepient and body of the e-mail. The body of the e-mail is received in a SAPTable format.
The SAP RFC calls a function written in C# on a windows server. This function takes all the parameters and creates an Outlook.MailItem object. Then this object is moved to the Sent Items folder of Outlook and then sent to the designated recepient.
Now, this program has started failing and is not able to send the required e-mails.
SAP is able to make the RFC and send the e-mail text etc. to the C# code, but the code is not able to send mail via Outlook. Following error message is generated:
"System.Runtime.InteropServices.COMException (0xC1F40102): Could not complete the operation because the service provider does not support it."
Could you please help me resolve this?
I brief idea of the code steps is as follows:
<span style="text-decoration:underline <span style="text-decoration:underline RFC function
protected override void Z_Rfc_Send_Mail (<br/>
string P_Buttons,string P_Order,string P_Subject,string P_To,ref TLINETable P_Table)<br/>
{<br/>
StringBuilder bodyHTMLText;<br/>
string sentTo = P_To;<br/>
<br/>
bodyHTMLText = new StringBuilder();<br/>
for (int i = 0; i < P_Table.Count; i++)<br/>
{<br/>
bodyHTMLText.Append(P_Table.Tdline);<br/>
}<br/>
try<br/>
{<br/>
OutlookMethod olMail = new OutlookMethod();<br/>
olMail.Outlook_SendMail(P_Buttons,P_Order,P_Subject,P_To,bodyHTMLText.ToString());<br/>
olMail = null;<br/>
}
:
:
} //end of RFC function
<span style="text-decoration:underline Outlook_SendMail method
Outlook.Application olApp; <br/>
Outlook.NameSpace olNS;<br/>
Outlook.MAPIFolder mailBox;<br/>
Outlook.MailItem olMail;
try <br/>
{<br/>
olApp = new Outlook.Application(); <br/>
olNS = olApp.GetNamespace("MAPI");<br/>
xx_mailBox = FindMailFolder(olNS.Folders, ConfigurationSettings.AppSettings["*******.Name"]) as Outlook.MAPIFolder;<br/>
<br/>
Outlook.MAPIFolder c_SentBox = FindMailFolder(xx_mailBox.Folders, "Sent Items") as Outlook.MAPIFolder;<br/>
olMail = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);<br/>
if (ConfigurationSettings.AppSettings["testTo"] == null)<br/>
{<br/>
olMail.Recipients.Add(P_To);<br/>
}<br/>
else<br/>
{<br/>
sentTo = ConfigurationSettings.AppSettings["testTo"];<br/>
olMail.Recipients.Add(sentTo);
}
//----------------------- email subject<br/>
olMail.Subject = P_Subject + " # " + P_Order;<br/>
//----------------------- HTML body
olMail.HTMLBody = bodyHTMLText;<br/>
LogFile("step 11 : bodyHTMLText is"+bodyHTMLText);
//---------------------- move the email to Sent Items folder for archives purpose<br/>
olMail.Move(c_SentBox);
olMail.Send();<br/>
//---------------------<br/>
olMail=null;<br/>
olNS = null;<br/>
olApp= null;
//Garbage Collection<br/>
GC.Collect();
--------------------------
We tried to hardcode the values for subject, order#, recepient, html body in the outlook.send_mail method and called this method directly (instead of calling it in the Z_RFC_Send_Mail function) This way the e-mail was generated successfully.
But when we it is called from the RFC/Z_RFC_Send_Mail function, then the above error message is encountered. We added some log points in the code and know that the Z_RFC_Send_Mail is able to call the Outlook.Send_Mail but within Outlook.Send_Mail the exception
is being thrown.
Sometimes, we also encounter the error message "Server Execution Failed". This usually comes at the beginning of the Try block in Outlook.Send_Mail method.
Itll be great if some one can help us resolve this issue.
Thanks for your time!
View the full article