lundi 11 mai 2015

VB.NET - How to use an OFT or a DOCX as a template when sending an email (Exchange Web Service)

I would like to send emails using ExchangeWeb Service by using either an OFT (Outlook Template) or word document as a template.

Here's how I send emails as of now (working):

    Public Sub SendEmailFrom3611(ByVal body As String, _
                                ByVal recipient As List(Of String), _
                                ByVal subject As String)

    Dim exch As ExchangeService = New ExchangeService(ExchangeVersion.Exchange2013)
    Const email3611 As String = "3611@domain.com"
    Const serviceNowUsr As String = "username"
    Const serviceNowPsw As String = "password"

    exch.AutodiscoverUrl(email3611)
    exch.Credentials = New WebCredentials(serviceNowUsr, serviceNowPsw)

    Dim email As New EmailMessage(exch)

    email.From = email3611
    email.ToRecipients.Add(email3611)

    For Each s As String In recipient
        email.ToRecipients.Add(s)
    Next s

    email.Subject = subject
    email.Body = body
    email.Body.BodyType = BodyType.HTML

    email.SendAndSaveCopy()

End Sub

Is it possible to use a word document as a template when sending emails? Before sending the email, I would look in the word document and replace some variables (like %FULLNAME%) with the actual name of the user.

Thanks, Gabriel

Aucun commentaire:

Enregistrer un commentaire