Then we declared some variables Email_Obj and Email_Configuration as Object.First, we named our Sub Procedure SendMail01.Here, after running this code, the message “ Heads up, enemy UAV spotted” will be sent to the recipient’s email address. If Err.Description "" Then MsgBox Err.Description Set Mail_Configuration = Email_Configuration.Fields Set Email_Configuration = CreateObject("CDO.Configuration") Set Email_Obj = CreateObject("CDO.Message") Message_Body = "Heads up, enemy UAV spotted." Type the following code in the VBA Module.We select this to send email using Gmail without Outlook. Check Microsoft CDO for Windows 2000 Library.In this section, we will only work with the dates. Let’s go through the process below for a better understanding. You can make a list of dates when you want to send the Emails to their corresponding recipients. We can send an Email automatically by using the Microsoft Visual Basic for Application (VBA) based on dates. Sending Single Email from Gmail Account Using Excel VBA Enter your Gmail username and the 16-digit app password into the respective fields.Related Articles Send Email from Excel VBA without Outlook: 4 Ways 1. Leave the smtpserver and smtpserverport fields as is when copying the code. With fields: This is where you configure your SMTP settings for your Gmail account.For the body, you can piece together components of the message by using the & string to insert data from any of the Microsoft Excel sheets right into the email message, just like shown above. From field needs to contain your Gmail address, but you're free to set the other fields however you want. With NewMail: This section contains all the parameters for sending your email, including the body of your email.MsgBox "Error encountered while sending email." & vbNewLine & Err.Number & ": " & Err.DescriptionĪnd these are the sections and fields you need to customize: MsgBox "Check your login credentials and try again." & vbNewLine & Err.Number & ": " & Err.Description MsgBox "Check your internet connection." & vbNewLine & Err.Number & ": " & Err.DescriptionĬase -2147220975 'Incorrect credentials User ID or password MsgBox "Your email has been sent", vbInformationĬase -2147220973 'Could be because of Internet Connection Item(msConfigURL & "/sendpassword") = "password" 'Your password or App Password Item(msConfigURL & "/sendusername") = 'Your gmail address Item(msConfigURL & "/sendusing") = 2 'Send using default setting Item(msConfigURL & "/smtpserverport") = 465 'Set the SMTP port Details Item(msConfigURL & "/smtpserver") = "" 'Set the SMTP server details Item(msConfigURL & "/smtpauthenticate") = 1 'SMTP authentication Enabled Item(msConfigURL & "/smtpusessl") = True 'Enable SSL Authentication Addattachment "c:\data\email.pdf" 'Duplicate the line for a second attachment. Addattachment "c:\data\email.xlsx" 'Optional file attachment remove if not needed. And here is some added data:" & Str(Sheet1.Cells( 2, 1)) TextBody = "This is the body of your email. Subject = "Send Email From an Excel Spreadsheet" This is what the complete code looks like: Sub Send_Emails() Paste all the code snippets below into your Module1 (Code) window. Keep in mind that while many of the fields are optional, the From and To fields are required. Now you're ready to create the mail objects and set up all the fields necessary to send an email.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |