简体   繁体   中英

Create outlook message with attachment using vb.net

I would like to create an outlook message with a subject and some attachments for the user to send when they are ready. I have the file paths for the attachments. How would I go about doing this?

Basically the user needs to click a button on the application and that open an outlook message window with a predefined message and a few attachments. They should then be able to modify and add the required "To" etc before sending via outlook.

Thanks!

How to send attachments in an e-mail message by using Visual Basic .NET

http://support.microsoft.com/kb/313803

Here is the C# version of the code:

void Main()
{
    // Create an Outlook application.
    Outlook._Application oApp;
    oApp = new Outlook.Application();

    // Create a new MailItem.
    Outlook._MailItem oMsg;
    oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem);
    oMsg.Subject = "Send Attachment Using OOM in Visual Basic .NET";
    oMsg.Body = "Hello World" + vbCr + vbCr;

    // TODO: Replace with a valid e-mail address.
    oMsg.To = "user@example.com";

    // Add an attachment
    // TODO: Replace with a valid attachment path.
    string sSource = "C:\\Temp\\Hello.txt";
    // TODO: Replace with attachment name
    string sDisplayName = "Hello.txt";

    string sBodyLen = oMsg.Body.Length;
    Outlook.Attachments oAttachs = oMsg.Attachments;
    Outlook.Attachment oAttach;
    oAttach = oAttachs.Add(sSource, , sBodyLen + 1, sDisplayName);

    // Send
    oMsg.Send();

    // Clean up
    oApp = null;
    oMsg = null;
    oAttach = null;
    oAttachs = null;
}

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