简体   繁体   中英

VB.Net Email Send

I have look around the internet but cannot see anything relevant. I just want to start a new email in outllook but do not want to send it as user may want to add their own things to the email and all my program is doing is adding a to address and attachment.

Any help will be greatly appreciated.

Here is an example - http://support.microsoft.com/kb/310263

// Create the Outlook application by using inline initialization.
Outlook.Application oApp = new Outlook.Application();

//Create the new message by using the simplest approach.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

//Add a recipient.
// TODO: Change the following recipient where appropriate.
Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("e-mail address");
oRecip.Resolve();

//Set the basic properties.
oMsg.Subject = "This is the subject of the test message";
oMsg.Body = "This is the text in the message.";

//Add an attachment.
// TODO: change file path where appropriate
String sSource = "C:\\setupxlg.txt";
String sDisplayName = "MyFirstAttachment";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;  
Outlook.Attachment oAttach = oMsg.Attachments.Add(sSource,iAttachType,iPosition,sDisplayName);

// If you want to, display the message.
// oMsg.Display(true);  //modal

//Send the message.
oMsg.Save();
oMsg.Send();

//Explicitly release objects.
oRecip = null;
oAttach = null;
oMsg = null;
oApp = null;

You can just call Process.Start on the outlook executable. There are switches to auto populate the message as well..

Open a new mail message:

outlook.exe /c ipm.note

Open a new mail message and populate sender:

outlook.exe /c ipm.note /m someone@example.com

Open a new mail message with attachment:

outlook.exe /c ipm.note /a filename

Combination:

outlook.exe /c ipm.note /m someone@example.com&subject=test%20subject&body=test%20body

You can use Process.Start("mailto:xxx") format. It will bring up default email client with format you put in mail to.

string mailto = string.Format(
            "mailto:{0}?Subject={1}&Body={2}&Attach={3}",
            address,subject,body,attach);

System.Diagnostics.Process.Start(mailto)

sorry to answer in c#.

The easiest way to do this is by using the Outlook COM interop -- Just add a COM reference to Outlook (it should use the Primary Interop Assembly if installed)

So something like:

Dim m_Email As New Microsoft.Office.Interop.Outlook.ApplicationClass
dim m_Message As Microsoft.Office.Interop.Outlook.MailItem = m_Email.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
m_Message.To = "me@example.com"
m_Message.Subject = "Subject"

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