Condividi tramite


Procedura: allegare file a elementi di posta elettronica di Outlook

In questo esempio viene allegato un file a un nuovo elemento di posta e viene inviato ad Armando Pinto. Nell'esempio si presuppone che come destinatario esista una persona denominata Armando Pinto.

Si applica a: le informazioni fornite in questo argomento sono valide per i progetti a livello di applicazione per Outlook 2007 e Outlook 2010. Per ulteriori informazioni, vedere Funzionalità disponibili in base ai tipi di progetto e applicazioni di Office.

Esempio

Private Sub ThisAddIn_Startup(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Me.Startup
    AddAttachment()
End Sub

Private Sub AddAttachment()
    Dim mail As Outlook.MailItem = _
    TryCast(Me.Application.CreateItem _
    (Outlook.OlItemType.olMailItem),  _
    Outlook.MailItem)

    mail.Subject = "An attachment for you!"

    Dim attachment As OpenFileDialog = _
        New OpenFileDialog()

    attachment.Title = "Select a file to send"
    attachment.ShowDialog()

    If attachment.FileName.Length > 0 Then
        mail.Attachments.Add( _
            attachment.FileName, _
            Outlook.OlAttachmentType.olByValue, _
            1, _
            attachment.FileName)
        mail.Recipients.Add("Armando Pinto")
        mail.Send()
    End If
End Sub
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    AddAttachment();
}

private void AddAttachment()
{
    Outlook.MailItem mail =
        this.Application.CreateItem
        (Outlook.OlItemType.olMailItem)
        as Outlook.MailItem;

    mail.Subject = "An attachment for you!";

    OpenFileDialog attachment = new OpenFileDialog();

    attachment.Title = "Select a file to send";
    attachment.ShowDialog();

    if (attachment.FileName.Length > 0)
    {
        mail.Attachments.Add(
            attachment.FileName,
            Outlook.OlAttachmentType.olByValue,
            1,
            attachment.FileName);
        mail.Recipients.Add("Armando Pinto ");
        ((Outlook._MailItem)mail).Send();
    }
}

Vedere anche

Attività

Procedura: inviare messaggi di posta elettronica a livello di codice

Procedura: salvare allegati da elementi di posta elettronica di Outlook

Procedura: creare un elemento di posta elettronica

Concetti

Utilizzo degli elementi di posta