A family of Microsoft relational database management systems designed for ease of use.
You can use
.SentOnBehalfOfName = "emailaddress"
somewhere below With objMail and above .Send
Thanks Hans
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi. For the method "CreateItem(olMailItem)"........ is there a way to send the e-mail directly without asking so that we can specify the source (e-mail) of the sender:
In this code .Display is used but I'm looking for something like .Send. Thanks.
Sub CreateHTMLMail() 'Creates a new e-mail item and modifies its properties Dim objMail As Outlook.MailItem 'Create e-mail item Set objMail = Application.CreateItem(olMailItem) With objMail 'Set body format to HTML .BodyFormat = olFormatHTML .HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY> Please enter the message text here. </BODY></HTML>" .Display <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<------------------------------------------------------------------HERE I WANTO TO SEND IT End With End Sub
A family of Microsoft relational database management systems designed for ease of use.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
You can use
.SentOnBehalfOfName = "emailaddress"
somewhere below With objMail and above .Send
Thanks Hans
You can use
.SentOnBehalfOfName = "emailaddress"
somewhere below With objMail and above .Send
You have to specify the recipient and preferably the subject:
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties
Dim objMail As Outlook.MailItem
'Create e-mail item
Set objMail = Application.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>>p><H2>The body of this message will appear in HTML.</H2></p>" & _
"<p>Please enter the message text here.</p></BODY></HTML>"
.To = "emailaddress"
.Subject = "my subject"
.Send
End With
End Sub
Remark: the above code should work in Outlook. You posted this in the Access forum; the code won't work in Access without modification. For example:
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties
Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem
On Error Resume Next
Set objOutlook = GetObject(Class:="Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = CreateObject(Class:="Outlook.Application")
objOutlook.Session.Logon
End If
On Error GoTo 0
'Create e-mail item
Set objMail = Application.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>>p><H2>The body of this message will appear in HTML.</H2></p>" & _
"<p>Please enter the message text here.</p></BODY></HTML>"
.To = "emailaddress"
.Subject = "my subject"
.Send
End With
End Sub
Sending directly works best if Outlook is already running; otherwise you run the risk that the message will remain in the Outbox until the next time you start Outlook interactively.
Hi. Thanks. But where do you specify the e-mail (source) ? the person who sends the e-mail.
Thanks.
You have to specify the recipient and preferably the subject:
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties
Dim objMail As Outlook.MailItem
'Create e-mail item
Set objMail = Application.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>>p><H2>The body of this message will appear in HTML.</H2></p>" & _
"<p>Please enter the message text here.</p></BODY></HTML>"
.To = "emailaddress"
.Subject = "my subject"
.Send
End With
End Sub
Remark: the above code should work in Outlook. You posted this in the Access forum; the code won't work in Access without modification. For example:
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties
Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem
On Error Resume Next
Set objOutlook = GetObject(Class:="Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = CreateObject(Class:="Outlook.Application")
objOutlook.Session.Logon
End If
On Error GoTo 0
'Create e-mail item
Set objMail = Application.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>>p><H2>The body of this message will appear in HTML.</H2></p>" & _
"<p>Please enter the message text here.</p></BODY></HTML>"
.To = "emailaddress"
.Subject = "my subject"
.Send
End With
End Sub
Sending directly works best if Outlook is already running; otherwise you run the risk that the message will remain in the Outbox until the next time you start Outlook interactively.