Created
March 20, 2019 12:50
-
-
Save Bardoctorus/694903271b35df077072492dbfa14348 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub send_email() | |
| Dim CDO_Config As Object | |
| Dim SMTP_Config As Variant | |
| Dim strSubject As String | |
| Dim strFrom As String | |
| Dim strTo As String | |
| Dim strCc As String | |
| Dim strBcc As String | |
| Dim strBody As String | |
| strSubject = "Results from Excel Spreadsheet" | |
| strFrom = "YOUR_EMAIL_HERE" ' the email address shown as from | |
| strTo = "RECIPIENT_EMAIL_HERE" ' the address you wish to send to | |
| strCc = "" | |
| strBcc = "" | |
| strBody = "The total results for this quarter are: " & Str(Sheet1.Cells(2, 2)) ' the cells to send - (column, row) e.g (B, 2) | |
| Set CDO_Mail = CreateObject("CDO.Message") | |
| On Error GoTo Error_Handling | |
| Set CDO_Config = CreateObject("CDO.Configuration") | |
| CDO_Config.Load -1 | |
| Set SMTP_Config = CDO_Config.Fields | |
| With SMTP_Config | |
| .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 | |
| .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 | |
| .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" ' change this to your smtp server address | |
| .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 | |
| .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "YOUR_EMAIL_HERE" ' your email address | |
| .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "YOUR_PSSWD_HERE" ' your password | |
| .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 ' your smtp server port may differ | |
| .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 | |
| .Update | |
| End With | |
| With CDO_Mail | |
| Set .Configuration = CDO_Config | |
| End With | |
| CDO_Mail.Subject = strSubject | |
| CDO_Mail.From = strFrom | |
| CDO_Mail.To = strTo | |
| CDO_Mail.TextBody = strBody | |
| CDO_Mail.CC = strCc | |
| CDO_Mail.BCC = strBcc | |
| CDO_Mail.Send | |
| Error_Handling: | |
| If Err.Description <> "" Then MsgBox (Err.Description & vbCrLf & Err.Number) | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment