Mail via VBA

  • Thread starter Thread starter nike
  • Start date Start date
N

nike

Hi,

I would like to send automated mails from Excel,
the basic stuff works fine, but I still need some help on details.
The following code will show you the function I call to create a mail.
I pass various data to this function.
The data gets passed on and inserted.

What I need is an option to move the sent mail
from the sent mail folder to another specified folder.

The approach I have coded doesn't work properly...

Apart from that I need some help on how I can force Outlook
to use the standard mail Template when creating a new mail...

My Outlook is set up to use a certain footer when creating a new mail,
but this setting doesn't get recognised when the mail is created with
vba...

Any help/input would be very appreciated.

Bye

Nike

Function SendMail(strRecip As String, strSub As String, strBod As
String, bolDel As Boolean) As String
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objSentFolder As Object
Dim objSentSubFolder As Object
Dim myNamespace As NameSpace
Dim obInboxFolder As Object
Dim mySentItems As Object
Set objOutlook = CreateObject("Outlook.Application")
Set myNamespace = objOutlook.GetNamespace("MAPI")
Set mySentItems = myNamespace.GetDefaultFolder(olFolderSentMail)
Set obInboxFolder = myNamespace.GetDefaultFolder(olFolderInbox)
On Error Resume Next
Set objSentFolder = obInboxFolder.Parent.folders("Reg Test")
If objSentFolder Is Nothing Then
Set objSentFolder = obInboxFolder.Parent.folders.Add("Reg Test")
End If

Set objSentSubFolder = objSentFolder.folders(Format(Date, "DDMMYY"))
If objSentSubFolder Is Nothing Then
Set objSentSubFolder = objSentFolder.folders.Add(Format(Date,
"DDMMYY"))
End If
On Error GoTo 0
Set objOutlookMsg = objOutlook.CreateItem(0) 'Create a mail item
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(strRecip)
Set objOutlookRecip = .Recipients.Add("CC user")
.Recipients(.Recipients.Count).Type = olCC

If Not objOutlookRecip.Resolve Then
SendMail = strRecip
Else
'MsgBox .Recipients(.Recipients.Count).Name
'I need the first Name of the recipient, but how?
'name returns the whole name...
.Subject = "Urgent - ..."
.Body = " - This mail was generated automatically - "
.Importance = olImportanceHigh
.DeleteAfterSubmit = bolDel
.Send
If bolDel = False Then
mySentItems.Items(1).Move objSentSubFolder
End If
End If
End With
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
End Function
 
Hi Sue,

thank you for your feedback, could you give me an example
on how you would code that?

It would be very nice of you.

Bye

Nike
 
Hi,
could you give me a hint on how I can insert a mailto Href Link inside
the html Body?

When I try to insert a mailto link it doesn't get recognised...

..HTMLBody = "A Link should follow:" & "<BR>" & _
"<a href=""mailto:[email protected]"">Test</a>

Any Info would be nice...

Bye

Nike
 
Your code below is missing a closing quotation mark, which you'd see if you
tested the HTML string before setting HTMLBody to it. Try:

strHTML = "A Link should follow:" & "<BR>" & _
"<a href=" & Chr(34) & "mailto:[email protected]" & _
Chr(34) & ">Test</a>"
MsgBox strHTML
.HTMLBody = strHTML

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



nike said:
Hi,
could you give me a hint on how I can insert a mailto Href Link inside
the html Body?

When I try to insert a mailto link it doesn't get recognised...

.HTMLBody = "A Link should follow:" & "<BR>" & _
"<a href=""mailto:[email protected]"">Test</a>

Any Info would be nice...

Bye

Nike

Sue Mosher [MVP-Outlook] <[email protected]> wrote in message
To file the sent message in another folder in your default information store, set the SaveSentMessageFolder property before you send the message.

If you need to add boilerplate text at the end of the message, include
that text when you set the Body property (or perhaps HTMLBody would be more
appropriate).
 
Hi Sue,

thank you for your info.

Bye

Nike

Sue Mosher said:
Your code below is missing a closing quotation mark, which you'd see if you
tested the HTML string before setting HTMLBody to it. Try:

strHTML = "A Link should follow:" & "<BR>" & _
"<a href=" & Chr(34) & "mailto:[email protected]" & _
Chr(34) & ">Test</a>"
MsgBox strHTML
.HTMLBody = strHTML

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



nike said:
Hi,
could you give me a hint on how I can insert a mailto Href Link inside
the html Body?

When I try to insert a mailto link it doesn't get recognised...

.HTMLBody = "A Link should follow:" & "<BR>" & _
"<a href=""mailto:[email protected]"">Test</a>

Any Info would be nice...

Bye

Nike

Sue Mosher [MVP-Outlook] <[email protected]> wrote in message
To file the sent message in another folder in your default information store, set the SaveSentMessageFolder property before you send the message.

If you need to add boilerplate text at the end of the message, include
that text when you set the Body property (or perhaps HTMLBody would be more
appropriate).
 
Back
Top