简体   繁体   中英

Sending Mail from .NET C# using activesync

I cannot find any example in C# code (nor other languages and platforms) with send mail implementation. I managed to find and dl code example with provisioning and folder sync tasks, but cannot find send mail example.

This is all from MSDN: http://msdn.microsoft.com/en-us/library/ee202897(v=exchg.80).aspx

BR, JDK

You could consider the Microsoft.Exchange.WebServices.dll. Sorry the example below is a bit rough as it is a cut down version of a much bigger class I use.

VB.NET:

Imports Microsoft.Exchange.WebServices.Data
    Public Class Exchange

             Public Sub SendEmail(fromEmailAddress As String, toEmailAddress As String, body As String, subject As String)

         Dim exService = New ExchangeService(serverVersion)
            exService.AutodiscoverUrl(fromEmailAddress)


            Dim msg As New EmailMessage(exService)
            msg.Subject = subject

            msg.Body = body

         msg.ToRecipients.Add(New Microsoft.Exchange.WebServices.Data.EmailAddress(toEmailAddress,toEmailAddress))

            msg.SendAndSaveCopy()

    End Sub
End Class

C#

    using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using Microsoft.Exchange.WebServices.Data;

public class Exchange
{

    public void SendEmail(string fromEmailAddress, string toEmailAddress, string body, string subject)
    {

        dynamic exService = new ExchangeService(serverVersion);
        exService.AutodiscoverUrl(fromEmailAddress);


        EmailMessage msg = new EmailMessage(exService);
        msg.Subject = subject;

        msg.Body = body;

        msg.ToRecipients.Add(new Microsoft.Exchange.WebServices.Data.EmailAddress(toEmailAddress, toEmailAddress));

        msg.SendAndSaveCopy();

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM