Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi All, I need to send a mail fr 1

Status
Not open for further replies.

nateshk

Programmer
Jan 16, 2001
49
HK
Hi All,

I need to send a mail from Word document using a macro. The mail will contain some message and additional the document itself will have to be sent as attachment.

Any Help ?????

Thanx in advance

Natesh
 
Natesh,

try the SENDMAIL method. If that doesn't meet yor requirements, set the HasRoutingSlip property of the doc you want to send to TRUE, then add Recipient, Subject and Message properties

Example
Code:
ThisDocument.SendMail
or:
Code:
ThisDocument.HasRoutingSlip = True

With ThisDocument.RoutingSlip
  .AddRecipient "nikita6003@hotmail.com"
  .Subject = "a message for nikki"
  .Message = "this routing slip thing DOES add a note to your email bodytext saying that the email's been routed and you can formward it on once you're done with it"
End With
HTH

Cheers
Nikki
 
Hi Nikita,

I tried out u r 2nd option, but nothing seemed to happen so i used "ThisDocument.SendMail" after setting properties of
RoutingSlip.

But it gave me a message of including it in my address book.
After i included an address in the address book, the mail was sent to the mail id i added in my addressbook and not to the mail id in the code.

Iam using win 2k and office 2k.

Is there any way to avoid it.

Can u help me out ?

Thanx
 
In Word (unlike in Excel), document.sendmail only opens up a window for the user to fill in where to send it. You can use sendkeys to fill in the recipient. However, for some reason I can't seem to get sendkeys to actually send the e-mail. Manually, either alt-S or ctrl-Enter works to send the e-mail out, but neither works from sendkeys. Maybe someone else can help explain this...
Rob
[flowerface]
 
Hi,
for the second option to send the mail you need to add this line of code:
Code:
ThisDocument.Route
after the End With.

As for why sendkeys doesn't work - dunno. Had the same problem with the PDFWriter addin supplied by Adobe. It worked intermittently. Ended up having to crack the PDFWriter code & rewriting it.

Try the extra line for the HasRoutingSlip method. That ought to work ;-)

Cheers
Nikki
 
Hi,

i tried using Route method. It still gives me the message
"No Matches found for XYZ" and i have to make an entry in my address book

Is there any way to prevent this.

Also i need to send the mail to multiple persons thru the macro.

with the persent code, i declare an array containg 2 mail ids and use a loop to send the mail to the addrs in the array.
But both the mails contain the 1st id only.

Hope u can help me.

Regards

Natesh
 
Hiya,

I've set up this code which allows you to send one document more than once to a set of different users. It uses a user-defined type, which contains the info necesary to create ONE message.

Code:
Private Type RoutingSlipRecipients
    sRecipient() As String
    sMessage As String
    sSubject As String
End Type

Sub TEST()
    Dim l_udtMessages() As RoutingSlipRecipients
    Dim l_iMessages As Integer
    Dim l_iRecipients As Integer
    
    'Set up recipients for 2 emails
    'first message
    ReDim l_udtMessages(0)
    l_udtMessages(0).sMessage = "a message for nikki"
    l_udtMessages(0).sSubject = "this routing slip thing DOES add a note to your email bodytext saying that the email's been routed and you can formward it on once you're done with it"
    
    'first message first recipient
    ReDim l_udtMessages(0).sRecipient(0)
    l_udtMessages(0).sRecipient(0) = "nikita6003@hotmail.com"
    'first message second recipient
    'as you've now got data in your array you MUST use Redim Preserve
    'to preserve what you've already got
    ReDim Preserve l_udtMessages(0).sRecipient(1)
    l_udtMessages(0).sRecipient(1) = "e.scheffers@mmguide.nl"
    
    'second message
    ReDim Preserve l_udtMessages(1)
    l_udtMessages(1).sMessage = "FYI"
    l_udtMessages(1).sSubject = "Message is FYI only; no need to reply."
    
    'second message first recipient
    ReDim Preserve l_udtMessages(1).sRecipient(0)
    l_udtMessages(1).sRecipient(0) = "e.scheffers@mmguide.nl"
    'second message second recipient
    ReDim Preserve l_udtMessages(1).sRecipient(1)
    l_udtMessages(1).sRecipient(1) = "nikita6003@hotmail.com"
    'keep adding recipients as needed
    
    'Set routing slip
    ThisDocument.HasRoutingSlip = True
    
    For l_iMessages = 0 To UBound(l_udtMessages)
        'add routing slip email message info
        With ThisDocument.RoutingSlip
          .Delivery = wdAllAtOnce
          For l_iRecipients = 0 To UBound(l_udtMessages(l_iMessages).sRecipient)
            .AddRecipient l_udtMessages(l_iMessages).sRecipient(l_iRecipients)
          Next l_iRecipients
          .Subject = l_udtMessages(l_iMessages).sSubject
          .Message = l_udtMessages(l_iMessages).sMessage
        End With
        'Route message
        ThisDocument.Route
    Next l_iMessages

End Sub


The reason for the dialog box is probably that your email program is prompted by Word to set the SentBy field, which Word sets to be the username as defined in Tools>Options ... and the names probably do not match
Try setting this name as the standard user of the mail app that you are using, or add the name to the address book.

HTH!

Cheers
Nikki
 
Hi Nikki,

First , thanx for all the effort you have put for answering my query. you have been quite helpfull and it is highly appreciated.

your code works fine well. i still do get the msg box,but that is no problem

but a new requirement has arised. u r code sends the mail to all the ids together. i want to sent the mail seperately.
ie; at present mail ids x,y,z appear together in the To : field. I want to send message seperately to x , y and z.

Hope you can help me on this one also..

Thanx in advance....

Natesh

 
Hi Nikki,

I have given you a star for your earlier suggestion

Thanx a ton.

Regards.

Natesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top