Hi everyone, i am new here and my first post. i'd like to send email from excel using vbcript. how i code it so that the email are sent to the distribution list in my outlook 2003 contacts. below is the codes for sending mail to indivual email addresses. Any help would be appriciated: Code: Sub Senmail() Dim objOutlook As Object Dim objOutlookMsg As Object Set objOutlook = CreateObject("Outlook.Application") Set objOutlookMsg = objOutlook.CreateItem(0) With objOutlookMsg .To = "name@email.com" .Cc = "name@email.com" .Subject = "Hello World (one more time)..." .Body = "This is the body of message" .HTMLBody = "HTML version of message" .Attachments.Add ("f:\Test.txt") .Send 'Let´s go! End With Set objOutlookMsg = Nothing Set objOutlook = Nothing End Sub Thanks Bulleye
Ee have to look at each and every item in the Contacts folder and check to see if the item happens to be a distribution list. If it is, we can then bind to that item (the distribution list) and methodically collect all the members and send them a mail. Code: Const olFolderContacts = 10 sDistName = "Friends" 'set the distribution list name here Set objOutlook = CreateObject("Outlook.Application") Set objNamespace = objOutlook.GetNamespace("MAPI") Set colContacts = objNamespace.GetDefaultFolder(olFolderContacts).Items intCount = colContacts.Count For i = 1 To intCount If TypeName(colContacts.Item(i)) = "DistListItem" Then Set objDistList = colContacts.Item(i) sEmails = ""; If objDistList.DLName = sDistName Then For j = 1 To objDistList.MemberCount sEmails = sEmails & ";" & objDistList.GetMember(j).Address Next 'send the mail using the emails u got! ;-) enjoy End if End If Next
Thanks so much for the reply Pradeep. Please excuse my VB ignorance but how can I intergrate your codes to make it work. I added your codes to my and it didn't compile.
could you please tell me what to do to display the body of the mail line by line. and also if we want to display multiple number of items using a forloop..what to do?? thanks for your code for how to send mail from vb
When we are sending mail from VB script, we specify, with <object> .To , .CC, .subject, .body, .html, .send in this, in body, we can enter only text. What I am asking is, I want to get the data in the body of mail line by line. To get line by line, is there any property to be specified in .body section? Also I'm having Array of values. I want to display them in the mail in the body section. How can we do that? Hope you got my question... Thanks smileyshowers
The HTMLBody is optional, you can only specify the text body if you want. To print an array of values, concatenate each array value into a string and then put it in the mail body. And btw, I still didnt get what you mean by want to get the data in the body of mail line by line.
I want the text of the body to be displayed as line by line: "This is my name. I am doing job. I am working." instead of "This is my name.I am doing job. I am working." (This is concatenation)
Code: strA = "This is my name." strB = "I am doing job." strC = strA & vbCrLf & strB; This gives: Code: This is my name. I am doing job.
Thanks pradeep.. One more query............ When i use the above code to send mail, after the mail gets triggered from VB, a dialogue box occurs on the desktop asking "Yes","No","Cancel". is there any code that automatically "Yes" must get clicked without user interaction. Can you suggest any solution for that.
It doesn't ask for confirmation by default, there must be some code which triggers the confirmation dialog box.
I am also getting this box. This pop up comes from Outlook saying: "A program is trying to automatically send e-mail on your behalf. Do you want to allow this? If this is unexpected, it may be a virus and you should choose no." THen there's a yes and no button for you to choose. Without choosing this button, the email will not run. Has anyone figured out how to get around this message? Any help will be appreciated. Thanks!
Just figured out that this pop up only occurs in 2003. I tried it in 2002, and no box came up. If anyone knows of a solution please let me know. Thank you!
Hi everyone, I am new to this subject. I managed to use the code from the first post and it works fine for me. However when I send an email manually I have Word as an editor for emails and I am able to insert all kinds of formatting, for example Bold font or bullets for numbering items in a list. Can I insert formatting in .body or HTMLBody? Can you advise how to achieve this? Thanx
Hi, I found this while looking for something else.... The box you are seeing is due to the enhanced security in Outlook 2003 and can't be disabled. There are soloutions out there like ExpressClickYes, but personally I opted to look at Redemption (http://www.dimastr.com/redemption/) This allows you to access outlook and bypass the enhanced security. Hope this helps!