Programatically click the Send button.

M

Marketware

I have a program that pastes the contents of a word document into an email
message. (See Below)

Now what I need to do is programatically click the Send button.

I realize there are easier ways to send an email, but I need to be able to
cut and paste exactily what is in the word document.

The question is, how to use either the inspector object or whatever to click
that send button.

mail = (Outlook.MailItem)oMailFolder.Items.Add(Outlook.OlItemType.olMailItem);

object start = WordApp.MergeDoc.Content.Start;
object end = WordApp.MergeDoc.Content.End;
Word.Range range = WordApp.MergeDoc.Range(ref start, ref end);

range.Copy(); //Put Contents into clipboard

inspector = mail.GetInspector;
if (inspector.EditorType == OlEditorType.olEditorWord)
{
Word.Document WordEditor = (Word.Document)inspector.WordEditor;
start = WordEditor.Content.Start;
end = WordEditor.Content.End;

Word.Range range2 = WordEditor.Range(ref start, ref end);

range2.Paste();

}

//Click Send Button

Thanks!!

bob
 
S

Sue Mosher [MVP]

You already have the message as the mail object, so just call mail.Send
 
M

Marketware

Sue,

You are right. But at first I was having a problem getting the contents of
the word document to go when I used mail.Send(). I added mail.Save(), and
everything works fine with one exception. It's putting the email in the
drafts folder, and doesn't leave the drafts until the automatic send/receive
occurs (every 5 Min. on my system).

Is this the best practice? Or should I try to force the Send/Receive? and
if So, can you direct me on forcing a Send/Receive?

Thanks again.

bob
You already have the message as the mail object, so just call mail.Send
I have a program that pastes the contents of a word document into an email
message. (See Below)
[quoted text clipped - 33 lines]
 
M

Marketware

I guess I spoke too soon. The emails looked great in the Drafts folder with
the body of the Word Document merged into the body of the email just fine.
But, when they returned (I sent them to myself) the body of the email was
empty. Have you ever seen this behavior before?

bob
Sue,

You are right. But at first I was having a problem getting the contents of
the word document to go when I used mail.Send(). I added mail.Save(), and
everything works fine with one exception. It's putting the email in the
drafts folder, and doesn't leave the drafts until the automatic send/receive
occurs (every 5 Min. on my system).

Is this the best practice? Or should I try to force the Send/Receive? and
if So, can you direct me on forcing a Send/Receive?

Thanks again.

bob
You already have the message as the mail object, so just call mail.Send
I have a program that pastes the contents of a word document into an email
message. (See Below)
[quoted text clipped - 33 lines]
 
M

Marketware

Another update. It appears as if it loses the body of the email going from
the Drafts folder to the Sent Items folder. Weird. I'd love a guess at
what's happening.
You already have the message as the mail object, so just call mail.Send
I have a program that pastes the contents of a word document into an email
message. (See Below)
[quoted text clipped - 33 lines]
 
S

Sue Mosher [MVP]

I haven't seen that behavior, but I would use a different approach to
transferring the content.

Since this forum is officially discontinued, I suggest we continue the
conversation in the Outlook Developers forum at
http://social.msdn.microsoft.com/Forums/en-US/outlookdev/threads
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54



Marketware said:
I guess I spoke too soon. The emails looked great in the Drafts folder with
the body of the Word Document merged into the body of the email just fine.
But, when they returned (I sent them to myself) the body of the email was
empty. Have you ever seen this behavior before?

bob
Sue,

You are right. But at first I was having a problem getting the contents of
the word document to go when I used mail.Send(). I added mail.Save(), and
everything works fine with one exception. It's putting the email in the
drafts folder, and doesn't leave the drafts until the automatic send/receive
occurs (every 5 Min. on my system).

Is this the best practice? Or should I try to force the Send/Receive? and
if So, can you direct me on forcing a Send/Receive?

Thanks again.

bob
You already have the message as the mail object, so just call mail.Send
I have a program that pastes the contents of a word document into an email
message. (See Below)
[quoted text clipped - 33 lines]

bob

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top