Ian Letters
unread,May 4, 2012, 5:56:01 AM5/4/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I am trying to send emails using VBA but using an email account in Outlook 2010
The following code has been working find for sending emails using our Exchange Account in Outlook but when I try to use another account in Outlook 2010 it doesn't. I am not an experienced programmer in VBA but can using work my way around things. The code pasted below is what works fine: The .SentOnBehalfOfName = GetCompanyDetails("ScCompanyEmail") get the name from a table to send the email from in Exchange and this work fine no problem. The problem comes when I replace the .sendOnBehalfofName with the .SendUsingAccount = "strEmailAccount" line of code. The account talktalk is valid within Outlook 2010 but I can't see why is doesn't work and hope that someone out there might be able to help me please.
Function SendEmailSc(varRecipient As Variant, strSubject As String, strMsg As String) As Boolean
On Error GoTo HandleErr
Dim oLApp As Outlook.Application
Dim objnewmail As MailItem
Dim strEmailAccount As String
If varRecipient = "@" Then
MsgBox "Invalid E-Mail address '" & varRecipient & "'.", vbInformation, gstrSystem
GoTo ExitHere
End If
Set oLApp = New Outlook.Application
Set objnewmail = oLApp.CreateItem(olMailItem)
'strEmailAccount = "talktalk"
With objnewmail
'.SendUsingAccount = "strEmailAccount"
.SentOnBehalfOfName = GetCompanyDetails("ScCompanyEmail")
.Recipients.Add varRecipient
.Recipients.ResolveAll
.Subject = strSubject
'.Body = strMsg
.HTMLBody = strMsg
.Save
.send
End With
SendEmailSc = True
ExitHere:
Exit Function
' Error handling block added by Error Handler Add-In. DO NOT EDIT this block of code.
' Automatic error handler last updated at 11-13-2000 11:15:38 'ErrorHandler:$$D=11-13-2000 'ErrorHandler:$$T=11:15:38
HandleErr:
Select Case Err.Number
Case 70
MsgBox "Network/Modem Disconnected.", vbCritical, gstrSystem
Resume ExitHere
Case Else
Select Case errorhandler(Err.Number, Err.Description, "basEMAIL.SendEmail") 'ErrorHandler:$$N=basEMAIL.SendEmail
Case 1
Resume ExitHere
Case 2
Resume Next
Case 3
Resume
End Select
End Select
' End Error handling block.
End Function