Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is an interface

C#
public interface IService1
  {
      [OperationContract]
      void InsertMails(UserMail mail);
  }

  // Use a data contract as illustrated in the sample below to add composite types to service operations.

  [DataContract]
  public class UserMail
  {
      string Sender = string.Empty;
      string Receiver = string.Empty;     
      Attachments attachment = null; //using Microsoft.Office.Interop.Outlook;

      [DataMember]
      public string MailSender
      {
          get { return Sender; }
          set { Sender = value; }
      }
      [DataMember]
      public string MailReceiver
      {
          get { return Receiver; }
          set { Receiver = value; }
      }    
      [DataMember]
      public string mailAttachment
      {
          get { return attachment; }
          set { attachment = value; }
      }
  }



Here is definition for interface method

string attachments = "";
public void InsertMails(UserMail mail)
{
if (mail.mailAttachment != null)
{
if (mail.mailAttachment.Count > 0)
{
for (int i = 0; i < mail.mailAttachment.Count; i++)
{
attachments = mail.mailAttachment.FileName;
string fpath = HttpContext.Current.Server.MapPath("Attachments\\");
fpath = fpath + mail.mailAttachment[i].FileName;
mail.mailAttachment[i].SaveAsFile(fpath);
}
}
else
{
attachments = "";
}

}

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("InsertOutlookMails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Sender", mail.MailSender);
cmd.Parameters.AddWithValue("@Receiver", mail.MailReceiver);
cmd.Parameters.AddWithValue("Attachment",mail.mailAttachment);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
LogMessage = DateTime.Now + " Details inserted successfully";
}
else
{
LogMessage = DateTime.Now + " Details not inserted successfully";
}
con.Close();
}
}

And here is my Add-in code

OutlookServiceReference.Service1Client objService = new OutlookServiceReference.Service1Client();
OutlookServiceReference.UserMail objMail = new OutlookServiceReference.UserMail();

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemSend += new ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
this.Application.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
}

void Application_NewMailEx(string EntryIDCollection)
{
NameSpace outlookNS = this.Application.GetNamespace("MAPI");
MailItem mail = (MailItem)outlookNS.GetItemFromID(EntryIDCollection, Type.Missing);
GetMails(mail);
}

private void Application_ItemSend(object Item, ref bool Cancel)
{
MailItem mail = (MailItem)Item;

GetMails(mail);
}

public void GetMails(MailItem mail,int flag)
{

objMail.MailSender = Sender;
objMail.MailReceiver = mail.To;
objMail.mailAttachment = mail.Attachments;

objService.InsertMails(objMail);
}

i'm facing problem when i pass mail.Attachments to the method b'coz Microsoft.Office.Interop.Outlook.Attachments converts to object type n thats why m not able to set mail.Attachments to objmail object

Is there any way to pass mail.Attachments or MailItem to wcf service


Thanks
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900