Any idea, any comment?
My goal is to send an email and get confirmation that the user has read the email.
I wrote a short application representing dll ie. VFP will use it as a COM object.
Note:
this all works fine as a COM object in VFP, but I wonder are the correct (enough) commands for my goal:
message.IsDeliveryReceiptRequested = true;
message.IsReadReceiptRequested = true;
Is this a good way:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
using System.Runtime.InteropServices;
using System.Linq;
namespace msexchsendemaildll
{
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ImyTestDLL
{
[DispId(0)]
string To { get; set; }
[DispId(1)]
string CC { get; set; }
[DispId(2)]
string cSubject { get; set; }
[DispId(3)]
string cBody { get; set; }
[DispId(4)]
string cprilozi { get; set; }
[DispId(5)]
string cusername { get; set; }
[DispId(6)]
string clozinka { get; set; }
[DispId(7)]
void Posalji();
}
[ComSourceInterfaces(typeof(ImyTestDLL))]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("MyESendCOM.MyClass")]
[ComVisible(true)]
public class MyTestSend : ImyTestDLL
{
public string To { get; set; }
public string CC { get; set; }
public string cSubject { get; set; }
public string cBody { get; set; }
public string cprilozi { get; set; }
public string cusername { get; set; }
public string clozinka { get; set; }
public void Posalji()
{
ExchangeService _service;
try
{
_service = new ExchangeService
{
Credentials = new WebCredentials(this.cusername , this.clozinka )
};
}
catch
{
return;
}
// office365 webservice URL
_service.Url = new Uri("
https://outlook.office365.com/EWS/Exchange.asmx");
EmailMessage message = new EmailMessage(_service);
MessageBody msgBody = new MessageBody();
msgBody.BodyType = BodyType.Text;
msgBody.Text = cBody;
message.Body = msgBody;
message.Subject = cSubject ;
message.IsDeliveryReceiptRequested = true;
message.IsReadReceiptRequested = true;
string[] imena = To.Split(';').ToArray();
foreach (string eadresa in imena )
{
message.ToRecipients.Add(eadresa);
}
string[] ccimena = CC.Split(';').ToArray();
foreach (string cceadresa in ccimena)
{
message.CcRecipients.Add(cceadresa);
}
string[] attach = cprilozi.Split('#').ToArray();
if (cprilozi.IndexOf('#') > 0)
{
foreach (string prilogfajl in attach)
{
message.Attachments.AddFileAttachment(prilogfajl);
}
}
else
{
message.Attachments.AddFileAttachment(cprilozi);
}
message.SendAndSaveCopy();
}
}
}