0

Possible Duplicate:
Send e-mail through VBA
Send email from Excel in Exchange environment

I have this so far

Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
objMailItem.Display
strEmailAddr  = "me.me@you.com"
objMailItem.Recipients.Add strEmailAddr
objMailItem.Body = "Hi"
objMailItem.Attachments.Add "access.xml"
Set objMailItem = nothing
Set objOutl = nothing

It works! But only on computers that have Outlook. How can I get this to work with computers that have Windows Live?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1513192
  • 1,123
  • 4
  • 17
  • 29
  • What application will run this script? e.g Access do have options to send an mail via `DoCmd.SendObject acSendNoObject, , acFormatHTML, empfängerMail, , , betreff, mailText` – Pilgerstorfer Franz Sep 04 '12 at 18:48
  • I just run the .vbs File, I am not familiar with them – user1513192 Sep 04 '12 at 20:09
  • Possible duplicate of [Recipients.Add generates Runtime error '287': Application-defined or object-defined error](https://stackoverflow.com/questions/1265270/recipients-add-generates-runtime-error-287-application-defined-or-object-defi) – Cœur Jul 14 '18 at 14:19

2 Answers2

1

Windows Live Mail (WLM) doesn't support automation via VBA, so it isn't as straightforward as with Outlook.

For other options, try typing [vba] e-mail in the search field. You'll get quite a few hits; here is a relevant sample: Hit, hit, hit. Some of these give you working code for sending mail using CDO. This is what I would do if I were you.

If you must use WLM, then have a look at this mail add-ins for Excel which does support WLM.

Otherwise you're stuck using VBA's SendMail method, which is very limited:

  • Can only send an Excel object such as a sheet, workbook, chart, range, etc.
  • Can't write text in the body of the e-mail
  • Can't use the CC or BCC fields
  • Can't attach files (other than the Excel object calling the method)

Example code:

Dim wb As Workbook
Set wb = ActiveWorkbook
wb.SendMail "me.me@you.com", _
            "Insert subject here"

For more examples look here: http://www.rondebruin.nl/sendmail.htm

Community
  • 1
  • 1
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
0

the following suppose to work on access (vba) (code is not mine):

Public Function send_email()

Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") =   "mygmail@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
.Update
End With
' build email parts With cdomsg
.To = "somebody@somedomain.com"
.From = "mygmail@gmail.com"
.Subject = "the email subject"
.TextBody = "the full message body goes here. you may want to create a variable to hold  the text"
.Send
End With
Set cdomsg = Nothing
End Function

note if you want to use other email service you should alter the code a bit.

some other options here - msdn reference

Hope it helps.

TheNewOne
  • 1,613
  • 11
  • 19