Hello guys!
I was searching forums and could not find the info on how to send email and insert "from" (see attached image).
my code now:
subject := "subject"
recipient := "recipient@gmail.com"
emailBody:= "body text"
from := "test@smth.dk" ; this is the mailbox that have to be in from.
Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email := email .GetNamespace("MAPI")
email.To := clientInfoFromGui.customerEmail
email.Subject := subject
email.To := recipient
email.SendUsingAccount := from
email.HTMLbody := emailBody
email.Display
Thank you in advance!!!
Send email via outlook with "From" inserted
Send email via outlook with "From" inserted
- Attachments
-
- from outlook.png (7.88 KiB) Viewed 940 times
- SuperFoobar
- Posts: 83
- Joined: 23 Nov 2018, 15:14
Re: Send email via outlook with "From" inserted
Have you tried ?
Code: Select all
email.From := "test@smth.dk"
Re: Send email via outlook with "From" inserted
Hi,
what you are looking for is, how to change the outlook-account sending from.
That works for me:
J.B.
what you are looking for is, how to change the outlook-account sending from.
That works for me:
Code: Select all
; change sending-Account ("from") to "xxx@google.com"
; Example, Source of knowledge: Account: https://docs.microsoft.com/de-de/office/vba/api/outlook.account
wanted_sender_address := "xxx@google.com"
if not (Citem.SendUsingAccount.smtpaddress == wanted_sender_address) ; if it is set already, nothing to change
{
olNameSpace := olApp.GetNamespace("MAPI")
Acc_Anzahl := olNameSpace.Accounts.count ; how many sending-accounts are registered in Outlook ?
loop, %Acc_Anzahl% ; which of those sending-accounts has that address in ?
{
if (olnamespace.accounts.item(a_index).SmtpAddress == wanted_sender_address)
{
Citem.SendUsingAccount := olNameSpace.Accounts.Item(A_Index)
break ; leave, we set it (the email's "from") to the email-address/sending-account we wanted
}
}
}
AHK: 1.1.37.01 Ansi, 32-Bit; Win10 22H2 64 bit, german
Re: Send email via outlook with "From" inserted
thank you for the replays!!!
This is what I have so far:
the problem is that this variable is empty: "Citem.SendUsingAccount.smtpaddress" and it only shows the first account which is nr 1 marked in the photo(see attached). Any suggestions?
subject := "subject"
recipient := "recipient@gmail.com"
emailBody:= "body text"
Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email.Subject := subject
email.HTMLbody := emailBody
wanted_sender_address := "erve@danskebank.lt"
if not (Citem.SendUsingAccount.smtpaddress == wanted_sender_address) ; if it is set already, nothing to change
{
olNameSpace := Outlook.GetNamespace("MAPI")
Acc_Anzahl := olNameSpace.Accounts.count ; how many sending-accounts are registered in Outlook ?
MsgBox, % "acc len: " Acc_Anzahl
loop, %Acc_Anzahl% ; which of those sending-accounts has that address in ?
{
MsgBox, % "acc name: " olnamespace.accounts.item(a_index).SmtpAddress
if (olnamespace.accounts.item(a_index).SmtpAddress == wanted_sender_address)
{
Citem.SendUsingAccount := olNameSpace.Accounts.Item(A_Index)
break ; leave, we set it (the email's "from") to the email-address/sending-account we wanted
}
}
}
email.Display
MsgBox, done
return
This is what I have so far:
the problem is that this variable is empty: "Citem.SendUsingAccount.smtpaddress" and it only shows the first account which is nr 1 marked in the photo(see attached). Any suggestions?
![Crazy :crazy:](./images/smilies/icon_crazy.gif)
subject := "subject"
recipient := "recipient@gmail.com"
emailBody:= "body text"
Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email.Subject := subject
email.HTMLbody := emailBody
wanted_sender_address := "erve@danskebank.lt"
if not (Citem.SendUsingAccount.smtpaddress == wanted_sender_address) ; if it is set already, nothing to change
{
olNameSpace := Outlook.GetNamespace("MAPI")
Acc_Anzahl := olNameSpace.Accounts.count ; how many sending-accounts are registered in Outlook ?
MsgBox, % "acc len: " Acc_Anzahl
loop, %Acc_Anzahl% ; which of those sending-accounts has that address in ?
{
MsgBox, % "acc name: " olnamespace.accounts.item(a_index).SmtpAddress
if (olnamespace.accounts.item(a_index).SmtpAddress == wanted_sender_address)
{
Citem.SendUsingAccount := olNameSpace.Accounts.Item(A_Index)
break ; leave, we set it (the email's "from") to the email-address/sending-account we wanted
}
}
}
email.Display
MsgBox, done
return
- Attachments
-
- email.png (26.55 KiB) Viewed 876 times
Re: Send email via outlook with "From" inserted
Hi,
oh sorry, because I dont want to publish the whole code, it would be more irritating than helpful, I missed an important part.
Here is what you need before the above mentioned code:
regards
J.B.
oh sorry, because I dont want to publish the whole code, it would be more irritating than helpful, I missed an important part.
Here is what you need before the above mentioned code:
Code: Select all
Citem:=ActiveInspector.CurrentItem ; current Item
Citem_Class:=Citem.class ; get class, class 43 for Emails, class 26 for appointments
; change sending-Account ("from") to "xxx@google.com"
; Account: https://docs.microsoft.com/de-de/office/vba/api/outlook.account
wanted_sender_address := "xxx@google.com"
if not (Citem.SendUsingAccount.smtpaddress == wanted_sender_address) ; it it is set already, nothing to change
{
olNameSpace := olApp.GetNamespace("MAPI")
Acc_Anzahl := olNameSpace.Accounts.count ; how many sending-accounts are registered in Outlook ?
loop, %Acc_Anzahl% ; which of those sending-accounts has that address in ?
{
if (olnamespace.accounts.item(a_index).SmtpAddress == wanted_sender_address)
{
Citem.SendUsingAccount := olNameSpace.Accounts.Item(A_Index)
break
}
}
}
J.B.
AHK: 1.1.37.01 Ansi, 32-Bit; Win10 22H2 64 bit, german
Re: Send email via outlook with "From" inserted
Hi again!
Thank you for the replay, but still I get nothing..
I do not understand what are Citem and Citem_Class. I think I am missing some of the functions or classes..
Any thoughts?
Thanks in advance!
^f1::
subject := "subject"
recipient := "recipient@gmail.com"
emailBody:= "body text"
Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email.Subject := subject
email.HTMLbody := emailBody
Citem:=ActiveInspector.CurrentItem
Citem_Class:=Citem.class
; Account: https://docs.microsoft.com/de-de/office/vba/api/outlook.account
wanted_sender_address := "xxx@google.com"
if not (Citem.SendUsingAccount.smtpaddress == wanted_sender_address)
{
olNameSpace := Outlook.GetNamespace("MAPI")
Acc_Anzahl := olNameSpace.Accounts.count
loop, %Acc_Anzahl%
{
if (olnamespace.accounts.item(a_index).SmtpAddress == wanted_sender_address)
{
Citem.SendUsingAccount := olNameSpace.Accounts.Item(A_Index)
break
}
}
}
email.Display
MsgBox, done
return
Thank you for the replay, but still I get nothing..
I do not understand what are Citem and Citem_Class. I think I am missing some of the functions or classes..
Any thoughts?
Thanks in advance!
^f1::
subject := "subject"
recipient := "recipient@gmail.com"
emailBody:= "body text"
Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email.Subject := subject
email.HTMLbody := emailBody
Citem:=ActiveInspector.CurrentItem
Citem_Class:=Citem.class
; Account: https://docs.microsoft.com/de-de/office/vba/api/outlook.account
wanted_sender_address := "xxx@google.com"
if not (Citem.SendUsingAccount.smtpaddress == wanted_sender_address)
{
olNameSpace := Outlook.GetNamespace("MAPI")
Acc_Anzahl := olNameSpace.Accounts.count
loop, %Acc_Anzahl%
{
if (olnamespace.accounts.item(a_index).SmtpAddress == wanted_sender_address)
{
Citem.SendUsingAccount := olNameSpace.Accounts.Item(A_Index)
break
}
}
}
email.Display
MsgBox, done
return
Who is online
Users browsing this forum: peter_ahk and 234 guests