Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
here is an interface
 
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 4-Nov-12 19:24pm

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

  Print Answers RSS
0 OriginalGriff 359
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 185
4 PIEBALDconsult 149
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2014
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