CDO / SMTP Email Help

Reegs

New Member
Joined
Aug 25, 2014
Messages
20
Let me start by saying that I am in NO WAY a programmer, and that I'm trying to learn as I go.

I'm trying to piece together some VB to send emails in Excel with CDO / SMTP.


The general Idea is:
1. Populate data throughout the day
2. At the end of shift, Press email button
3. Look at Table1 (F-O) and copy only the rows of data that have data in column F
4. Copy data to the body of the email and send it.


Here is what I have so far:


Code:
Sub SendEmailUsingSMTP()
 
Dim NewMail As CDO.Message
Dim strbody As String
Dim rng As Range
 
Set NewMail = New CDO.Message
 
'Enable SSL Authentication
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
 
'Make SMTP authentication Enabled=true (1)
 
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
 
'Set the SMTP server and port Details
 
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "MY_SERVER.com"
 
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 
'Set your credentials of your Account
 
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MY_ADDRESS@WORK.com"
 
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MY_PW"
 
'Update the configuration fields
NewMail.Configuration.Fields.Update
 
'Set All Email Properties
 
'Select only used cells
    Range("F1:O100").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=1, Criteria1:="<>"
    Columns("F:O").Select
   
 
Set rng = Selection
 
 
With rng
 
srtbody = rng
 
Range("F1").Activate
Selection.AutoFilter
Range("F2").Select
End With
 
With NewMail
  .Subject = "EOS Scrap Log"
  .From = "MY_ADDRESS@WORK.com"
  .To = "SOME_PEOPLE@WORK.com"
  .CC = ""
  .BCC = ""
  .TextBody = strbody
 
 
NewMail.Send
 
MsgBox ("Mail has been Sent")
 
'Set the NewMail Variable to Nothing
Set NewMail = Nothing
 End With
End Sub


I know what I have is wrong/horrible to look at, but I'm still learning.

No matter what I try, I can't seem to get it to work.
frown.gif


Please help me.

Reegs
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top