I have a form looking up email addresses in an excel sheet, which works fine in creating mailto hyperlinks. they look like this...
But I would like to show the person's actual name, like this, and I have the string available...
My question is whether this can be done in the way the link is constructed, or is this something the email client is doing by matching from the address book?
I would prefer to train the address book, rather than create email only addresses.
additionally here is a sample of what I have
Link = "mailto:" & EmpForm.Label10
whoTo = EmpForm.TextBox3 'which I want to use in the TO:whoever
ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
Instead of following the link from Excel, meaningly, remove this part:
ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
You could create a mail from Excel. Thus, you could set the parameters you want.
Here is a sample of code (found here):
' requires a reference to the Microsoft Outlook 8.0 Object Library
Sub SendAnEmailWithOutlook()
' creates and sends a new e-mail message with Outlook
Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail message
With olMailItem
.Subject = "Subject for the new e-mail message" ' message subject
Set ToContact = .Recipients.Add("name#domain.com") ' add a recipient
Set ToContact = .Recipients.Add("name#company.com") ' add a recipient
ToContact.Type = olCC ' set latest recipient as CC
Set ToContact = .Recipients.Add("name#org.net") ' add a recipient
ToContact.Type = olBCC ' set latest recipient as BCC
.Body = "This is the message text" & Chr(13)
' the message text with a line break
.Attachments.Add "C:\FolderName\Filename.txt", olByValue, , _
"Attachment" ' insert attachment
' .Attachments.Add "C:\FolderName\Filename.txt", olByReference, , _
"Shortcut to Attachment" ' insert shortcut
' .Attachments.Add "C:\FolderName\Filename.txt", olEmbeddedItem, , _
"Embedded Attachment" ' embedded attachment
' .Attachments.Add "C:\FolderName\Filename.txt", olOLE, , _
"OLE Attachment" ' OLE attachment
.OriginatorDeliveryReportRequested = True ' delivery confirmation
.ReadReceiptRequested = True ' read confirmation
'.Save ' saves the message for later editing
.Send ' sends the e-mail message (puts it in the Outbox)
End With
Set ToContact = Nothing
Set olMailItem = Nothing
Set OLF = Nothing
End Sub
To create your recipient field, you can use:
arrTo = Split(whoTo,"#")
whoTo = UCase(arrTo[0]) & " " & UCase(arrTo[1]) & "<" & whoTo & ">"
Outlook new mail window will show you name if the e-mail address you are mailing to is present in it's address book else full e-mail address is shown.
Related
MS Access 2019 form supplies data to send an email via Outlook 2019.
The recipient (email address) will not populate the email "To" box unless it is text, but will not if it is an email. When 'proving the VBA data transfer via msgbox, it will. I suspect it could be my dim declaration type but I have tried others such as string and variant(illustrated)
The code below will allow the MsgBox to run, but nothing else.
My form fields are named" 'Name' txtRecip, and 'EMail' txtEmail
Any ideas?
Thanks in advance
Fred
Private Sub btnSendEmail_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim objEmail As Variant
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application") ' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
objEmail = [txtEmail].Value
response = MsgBox(objEmail)
Set objOutlookRecip = .Recipients.Add(objEmail)
objOutlookRecip.Type = olTo
'response = MsgBox(txtName & Chr(13) & txtEmail)
' Add the CC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("")
' objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = "B2B - Brethren Outreach"
.Body = txtName.Value & "," & Chr(13) & Chr(13) & "
If you are using Linux, LibreCalc and thunderbird and need to send an email this might help you
Add an attachment
Specify multiple Recipients from Cell input
Send the email through Thunderbird without issues
Have a larger formatted body to the email
Specify CC(Carbon Copy) and BCC(Blind Carbon Copy)
The code below has instructions notated throughout to follow. Just copy the code and edit your LibreCalc sheet and the Macro code as needed.
REM ***** BASIC *****
Sub sendEmailWithAtachmentsAndFormatting
'Set variants to be used in the email
Dim oSheet1 As Variant
Dim oRangeUser As String ' Data of range, all cells of all rows in range
Dim oRangeClickableLinkFormattedInCalc As Variant ' Data of range, all cells of all rows in range
'Specifying the Calc sheet to be referenced.
'Replace the name FORM with whatever your Sheet name is; I have a Form setup to pull information from, so that's what I use
oSheet1 = ThisComponent.Sheets.getByName("FORM") 'Selects the FORM tab as the place to pull info from'
'Getting the email addresses(recepients) you want to send to
'Replace the Cells listed in the code with the ones you want referenced
oRangeUser1 = oSheet1.getCellRangeByName("K2").string 'Email Address 1'
oRangeUser2 = oSheet1.getCellRangeByName("K3").string 'Email Address 2'
oRangeUser3 = oSheet1.getCellRangeByName("K4").string 'Email Address 3'
oRangeUser4 = oSheet1.getCellRangeByName("K5").string 'Email Address 4'
oRangeUser5 = oSheet1.getCellRangeByName("K6").string 'Email Address 5'
oRangeUser6 = oSheet1.getCellRangeByName("K7").string 'Email Address 6'
oRangeUser7 = oSheet1.getCellRangeByName("K8").string 'Email Address 7'
oRangeUser8 = oSheet1.getCellRangeByName("K9").string 'Email Address 8'
oRangeUser9 = oSheet1.getCellRangeByName("K10").string 'Email Address 9'
oRangeUser10 = oSheet1.getCellRangeByName("K11").string 'Email Address 10'
'Getting the HTML link you want to use
'NOTE: you will need to forma the link in the cell for it to be used in the email properly LinkText
oRangeClickableLinkFormattedInCalc = oSheet1.getCellRangeByName("M1").string 'Specifies a blank template link with new parent ticket'
'Combining the emails(recepients) that the message is being sent to
'NOTE: The only way i could get Thunderbird to recognize seperate emails was using this format &";"& oRangeUser &";"&
' For somereason it only works with the ";" in the middle of each email
eMailAddress = oRangeUser1 &";"& oRangeUser2 &";"& oRangeUser3 &";"& oRangeUser4 &";"& oRangeUser5 &";"& oRangeUser6 &";"& oRangeUser7 &";"& oRangeUser8 &";"& oRangeUser9 &";"& oRangeUser10
'Specify email Subject
eSubject = "This is my email Subject Text"
'Specify email Body
' Your text must be contained within quotation marks: "Text here"
'If you want to make it easier to read your code, add an underscore at the end of your text and then write the next line of code below using & to connect the text, repeat as nessisary
'To combine strings of text use &, to combine Text with a Variable(link text etc) use "text"& varientName &"Text" Ensure that there is a space before and after the varient
'If you want to use special characters they must be seperate form the actual text for the system to recognize it
' colon(:) is : | comma(,) is ,
eBody = "Start of Your Email<br><br>" _
&"The br twice indicates you want a space between lines<br>" _
&"One br indicates next line" _
&"<ul>"_
&"<li>UnOrderedListOne</li>"_
&"<li>UnOrderedListTwo</li>"_
&"</ul>"_
&"<ol>"_
&"<li>OrderedListOne</li>"_
&"<li>OrderedListTwo</li>"_
&"</ol>"_
&"<b>SomeBoldText</b> <i>SomeItalicizedText</i>"_
&"Displaying a plain URL not linked - htttps"&":"&"//URLtext"_
&"Text before clickable link"& oRangeClickableLinkFormattedInCalc &"Text after the clickable link" _
&"The final line of your body dosnt need the underscore"
'Specify email setup informaiton
eMailer = createUnoService ("com.sun.star.system.SimpleCommandMail")
eMailClient = eMailer.QuerySimpleMailClient()
eMessage = eMailClient.createSimpleMailMessage()
'Specify Recipient(s) using information form FORM
eMessage.Recipient = eMailAddress
'Specify Carbon Copy Recipient(s) usingStatic text
eMessage.CcRecipient = Array("NAME#email.com")
'Specify BlindCarbon Copy Recipient(s) usingStatic text
'NOTE: I have this removed as its not needed for me
' eMessage.BccRecipient = Array("NAME#email.com")
eMessage.Subject = eSubject
eMessage.Body = eBody
'Specify where email attachment is coming from
AttachmentURL = convertToUrl("home/YourProfileName/Documents/DocName.pdf")
'Adding email attachment
eMessage.Attachement = Array(AttachmentURL)
eMailClient.sendSimpleMailMessage ( eMessage, com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE )
End Sub
I need to send a very simple email with only text to a few recipients, but I'm getting an error.
I don't have an SMTP server to send emails through, but I do have an outlook and I'm logged in through the desktop app.
Here's the script so far:
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
objMail.Display
objMail.to = "recipient#whatever.com"
objMail.Subject = "Test"
objMail.Body = "test"
objMail.Send
objOutlook.Quit
Set objMail = Nothing
Set objOutlook = Nothing
When the script is run, WSH gives the error
line: 10
char: 1
error: Operation Aborted
source: (null)
This is the objMail.Send line.
And my outlook pops up with the proper recipient/subject/body, but it doesn't send.
I can't find anything related to this issue or a work around besides using an SMTP server which as far as I know I can't do.
I have a function defined and in daily use which accepts the various items for creating and sending the email. Remember if you have to create your Outlook instance, you need to log on with the appropriate mail profile in order to send anything. The profile we use here is just called "Outlook". Check what yours is called and include the Namespace stuff I have in mine.
Dim sComputer : sComputer = "." ' selects local machine
Dim oWMIService : Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Dim colItems : Set colItems = oWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'outlook.exe'")
Dim oOutlook : Set oOutlook = CreateObject("Outlook.Application")
Dim oNamespace : Set oNamespace = oOutlook.GetNamespace("MAPI")
If colItems.Count = 0 Then
LOG_Write "Outlook isn't open, logging onto it..."
oNamespace.Logon "Outlook",,False,True ' name of Outlook profile
bOpenedOutlook = True
End If
Dim oFolder : Set oFolder = oNamespace.GetDefaultFolder(olFolderInbox)
oFolder.Display ' Make Outlook visible
Here is basic vbscript simple email
' For Example...
Email_List = "0m3r#Email.com;"
Set App = CreateObject("Outlook.Application")
Set Mail = App.CreateItem(0)
With Mail
.To = Email_List
.CC = ""
.BCC = ""
.Subject = "Hello World"
.HTMLBody = "Bla Bla!!!"
'.Body = strbody
'You can add a file like this
' .Attachments.Add (FilePath)
'use .Send (to send) or .Display (to display the email and edit before sending)
.Display
.send
End With
Set Mail = Nothing
Set App = Nothing
Save is as name.vbs
How to send a mail from MS Access Form. ?
Assume I have MS Access Application with a DashBoard form.
I have send mails to certain mail address
like sending a notification mail on clicking "send notification button"
How to do this with codebuilder in MS access
I found that you can send mail using this code snippet
Private Sub send_mail()
Dim olApp As Object
Dim objMail As Object
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = "abc#yourmailaddress.com"
.Cc ="ccaddress#yourmailaddress.com"
.Subject = "Subject LIne"
.HTMLBody = "<htmltags>Body Content</htmltags>"
.send
End With
MsgBox "Operation completed successfully"
End Sub
Source : Thread from Access Programmer site
I found some code that worked for email based on code that I was using to open a browser from a contact's home page, worked just fine and was a lot easier for me to understand. For opening a web page, delete the '"mailto:" & '.
Private Sub cmdEmailContact_Click()
Dim sWebPath As String
Dim sFullLinkPath As String
If IsNull(Me.ContactEmail) Then
MsgBox ("Can't create email: no address listed")
Exit Sub
End If
sWebPath = "mailto:" & Me.ContactEmail
sFullLinkPath = sWebPath
Application.FollowHyperlink sFullLinkPath
End Sub
I have a userform that helps different users fill in data into the spreadsheet. As soon as the data is inserted it should also be sent by email to a few recipients, depending on the options filled in the form.
This happens within a corporate environment using Exchange. I would create a new email account for this file to be able to send the email as an entity and not use the user's email account.
Is this possible? How? I have googled for it and all I can find is how to create a mail message that the user sends from his account.
I've used the code below (source) to send e-mails from Excel-VBA. I've only tested it with my own e-mail account, but I assume you could have it send mail from a different account (msgOne.from = ...), as long as the user has permission to send from that account on the Exchange server.
Dim cdoConfig
Dim msgOne
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServerPort) = 25 '465 ' (your port number) usually is 25
.Item(cdoSMTPServer) = "smtp.mysmtpserver.com" ' your SMTP server goes here
'.Item(cdoSendUserName) = "My Username"
'.Item(cdoSendPassword) = "myPassword"
.Update
End With
Set msgOne = CreateObject("CDO.Message")
Set msgOne.Configuration = cdoConfig
msgOne.To = "someone#somewhere.com"
msgOne.from = "me#here.com"
msgOne.subject = "Test CDO"
msgOne.TextBody = "It works just fine."
msgOne.Send
Unfortunately, I can't test this hypothesis at this time, as I'm only set up to send from one account. Let me know how it works out!
If the excel application is running on a machine with outlook, you can something along the following.
Function SendEmailWithOutlook(er As emailRecord,
recipients As String,
cc As String,
subject As String,
body As String,
attachmentPath As String) As Boolean
Dim errorMsg As String
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error GoTo errHandle
If (er.useTestEmail = True) Then
recipients = er.emailTest
cc = er.emailTest
End If
With OutMail
If er.emailFrom <> "" Then
.sentOnBehalfOfName = er.emailFrom
End If
.To = recipients
.cc = cc
.bcc = er.emailBcc
.subject = subject
.htmlBody = body
If attachmentPath <> "" Then
.Attachments.Add attachmentPath
End If
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
SendEmailWithOutlook = True
Exit Function
errHandle:
errorMsg = "Error sending mail via outlook: " & Err.Description & vbCrLf
errorMsg = errorMsg & "OnBehalfOf:" & er.emailFrom & vbCrLf
errorMsg = errorMsg & "Recipients: " & recipients & vbCrLf
errorMsg = errorMsg & "CC: " & cc & vbCrLf
errorMsg = errorMsg & "BCC: " & er.emailBcc
MsgBox errorMsg
SendEmailWithOutlook = False
End Function
Add a reference to Microsoft Outlook 14.0 Object Library
Why not use the Outlook Object Model?
You can give the current user the right to send on behalf of the specified user, then set MailItem.SentOnBehalfOfName and MailItem.ReplyRecipients (if necessary) properties before callign MailItem.Send.