|
-
Nov 1st, 2022, 01:20 PM
#1
Thread Starter
Lively Member
Sending email from a specified account (Outlook)
I have struggled to understand how to set my program to send email from a specified account in Outlook. I have multiple accounts and need to send email from a specific account so replies (if any are warranted) are sent back to the same account.
I have looked multiple places and either I am too dense to understand or I am completely missing the mark. The code below successfully opens Outlook populates the receiver's address, sets the subject and body fine. It just does not send via the proper account, always using the default email account, which forces me to adjust the sending account each time in Outlook an email is being sent. I just cannot figure out how to tell Outlook to use a specific eMail account.
Code:
Private Sub RtbBillEmail_MouseDoubleClick(sender As Object, e As EventArgs) Handles tbBillEmail.MouseDoubleClick
Cursor = Cursors.Hand
Dim oOLook As Object
Dim oEMail As Object
Dim eMailSubject As String = "Load: " + tbBrokerLoadNumber.Text + " Inquiry"
Dim eMailBody As String = "ENTER INQUIRY HERE"
Dim eMailCC As String = "[email protected]"
Dim eSender As String = "[email protected]"
oOLook = CreateObject("Outlook.Application")
oOLook.Session.Logon()
oEMail = oOLook.CreateItem(0)
oEMail.Display(False)
With oEMail
.Sender = eSender
.To = tbAgentEmail.Text
.CC = ""
.BCC = eMailCC
.Subject = eMailSubject
.HTMLBody = eMailBody
.ReadReceiptRequested = True
'Use the .Send() to auto Send the mail - not currently being used.'
'.Send()
End With
Cursor = Cursors.Default
End Sub
Last edited by K3JAE; Nov 1st, 2022 at 01:26 PM.
-
Nov 1st, 2022, 02:01 PM
#2
Re: Sending email from a specified account (Outlook)
The short answer is you can't ... You're opening Outlook and it's going to open using what ever profile it's designated for it.
If you want to send from an alt account, you're going to need to connect to an SMTP server, and send it - not that much differently, but with the From information set. Downside of this, the email doesn't end up in the Outbound or Sent folder for the account.
I'd be happily proven wrong on this, but that's the way it's worked for me in the past. (to get around the lack of a record in send, we'd also BCC send it to the account so that it at least ends up in the inbox so that sales reps would know that it was sent.
-tg
-
Nov 1st, 2022, 06:23 PM
#3
Re: Sending email from a specified account (Outlook)
It looks like it can be done with VBA, so there may be a way to use VB .Net also.
https://www.extendoffice.com/documen...send-from.html
-
Nov 1st, 2022, 07:11 PM
#4
Re: Sending email from a specified account (Outlook)
 Originally Posted by jdc2000
That's OutLook VBA. It works with OutLook because it's part of OutLook...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 1st, 2022, 08:10 PM
#5
Re: Sending email from a specified account (Outlook)
 Originally Posted by jdc2000
That works because it's manipulating Outlook. The alt account still has to be setup up in the Outlook client in order for that to work.
-tg
-
Nov 2nd, 2022, 03:10 AM
#6
Re: Sending email from a specified account (Outlook)
here a sample to send from the default Outlook, the Line you will have to change is..
Code:
oNameSpace.Logon(Nothing, Nothing, True, True)
instead of Nothing you place the MAPI Profil of the Account
Code:
Option Strict On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook
Public Class Form1
Private oApp As Outlook.Application
Private oNameSpace As Outlook._NameSpace
Private oOutboxFolder As Outlook.MAPIFolder
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
oApp = New Outlook.Application()
oApp = New Outlook.Application()
oNameSpace = oApp.GetNamespace("MAPI")
oNameSpace.Logon(Nothing, Nothing, True, True)
oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)
addToOutBox("[email protected]", "mySubject", "myBody", "D:\2013.pdf")
oNameSpace.Logoff()
End Sub
Public Sub addToOutBox(ByVal toValue As String, ByVal subjectValue As String, ByVal bodyValue As String, ByVal mAttach As String)
Dim oMailItem As Outlook._MailItem = CType(oApp.CreateItem(Outlook.OlItemType.olMailItem), Outlook._MailItem)
oMailItem.To = toValue
oMailItem.Subject = subjectValue
oMailItem.Body = bodyValue
oMailItem.Attachments.Add(mAttach)
oMailItem.SaveSentMessageFolder = oOutboxFolder
'adds it to the outbox
oMailItem.Save()
'oMailItem.Display(True)
'direct versenden
'oMailItem.Send()
End Sub
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Nov 2nd, 2022, 09:35 AM
#7
Thread Starter
Lively Member
Re: Sending email from a specified account (Outlook)
 Originally Posted by jdc2000
I did see this article prior to posting my original message but was unsure if that would even work. Especially when MS decides to force update Office 365 (and windows for that matter) and reset things back to the way they think we should want them, and how they definitely want them with little care about how we actually want them.
-
Aug 24th, 2025, 05:28 AM
#8
New Member
Re: Sending email from a specified account (Outlook)
 Originally Posted by techgnome
The short answer is you can't ... You're opening Outlook and it's going to open using what ever profile it's designated for it.
If you want to send from an alt account, you're going to need to connect to an SMTP server, and send it - not that much differently, but with the From information set. Downside of this, the email doesn't end up in the Outbound or Sent folder for the account.
I'd be happily proven wrong on this, but that's the way it's worked for me in the past. (to get around the lack of a record in send, we'd also BCC send it to the account so that it at least ends up in the inbox so that sales reps would know that it was sent.
-tg
You can only acheive VBA to use particular outlook profile by making it a "Default" email & "Default" outlook data file in the Account setting of outlook.
Whether it can be done programmatically using VBA & be reverted? I have no idea! Experts may help on it. (This may be worth a try : "https://www.extendoffice.com/documents/outlook/5600-outlook-choose-account-to-send-from.html")
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|