简体   繁体   中英

how to change the .from on the email I sent using vba for gmail?

I am sending email using a CDO.Message on vba from my gmail account. all works fine, however, on my

With Mail
    .From

I am inserting the email address I want to send it from. When it arrives, it arrives with the email address itself and not the name associated to the gmail account: .from = johndoe@gmail.com => the email will be received from "johndoe@gmail.com" instead of John Doe as defined on the gmail account.

Is there any way to get the name instead of the email address?

thanks,

all works fine except this detail.

     With Mail
               .Subject = subj
               .From = Range("acct").Value
               .To = dest
               '.To = Range("mailing").Offset(i, 0).Value
               .textbody = body
               If att = "" Then GoTo noatt
               attnb = 1
               While Not IsEmpty(Range("attachement").Offset(attnb, 0))
              .AddAttachment (Range("attachement").Offset(attnb, 0)) 'To attach Documents in mail
             attnb = attnb + 1
            Wend
noatt:
            End With
            'to send the mail
            Mail.Send

Try using the following syntax:

Name Surname <mymail@gmail.com>

So in your code it would be like:

.From = "John Doe <johndoe@gmail.com>" 

It should do the tricks.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM