Link to home
Start Free TrialLog in
Avatar of Eric Burton
Eric BurtonFlag for United States of America

asked on

EMERGENCY: Need to change sender when using Outlook mailitem object in VB.NET code

Hi everybody,

I am currently using an Outlook mailitem object to send email from within VB.NET. The mailitem object has properties for (To:), (Subject:) and (Attachments), but I don't see any way to change the sender.  Is a mailitem object appropriate for this?

Please see attached code example!
User generated image
Thanks for your help!
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try¨something like this
    Dim AccountName as String = "from@mail.com"
    Dim session As objOutlk.NameSpace = mail.Session
    Dim accounts As objOutlk.Accounts = session.Accounts
    For i As Integer = 1 To accounts.Count
        Dim account As objOutlk.Account = accounts(i)
        If account.SmtpAddress.ToLower() == AccountName.ToLower() Then
            mail.SendUsingAccount = account
            Exit For
        End If
    Next i

Open in new window

Regards
you can use .SenderEmailAddress if you are using outlook 2013 library.
https://msdn.microsoft.com/en-us/library/office/ff868262.aspx
@ yo_bee MailItem.SenderEmailAddress is read-only not tochange the sender
I cannot say for current versions of Outlook, but way back in 2003, we found out, as you seem to have done, that there was no way to change the sender with Outlook.

We found a low cost SMTP server at www.componentsource.com that was even easier to use than Outlook from VBA code, and that had all the features we wanted. My customer used it for years without any problem.
ASKER CERTIFIED SOLUTION
Avatar of yo_bee
yo_bee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial