Sub send_e_mail()
'==== DELAYS for 30 seconds to give file time to write to server
sngStartTimer = Timer ' Notes the current time in seconds
Do Until Timer - sngStartTimer >= 30 ' 30 sec delay
Str (Timer - sngStartTimer)
Loop
Dim iMsg As Object
Dim iConf As Object
' Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "yourserverdomain"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
With iMsg
Set .Configuration = iConf
'EDIT LIST TO SEND TO APPROPRIATE RECIPIENTS
.To = "person1; person2; person3; person4"
.CC = " person1; person2; person3; person4"
.BCC = ""
.From = """SENDER"" <sender@email.com>"
.Subject = "Subject_Here"
.HTMLBody = RangetoHTML
.AddAttachment "c:\file_location\"
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
End Sub
Public Function RangetoHTML()
'Creates temp HTML file from data contained on shopAmex template
'
Sheets("HTML_mail_format").Select
Range("A1:A13").Select
Dim fso As Object
Dim ts As Object
Dim TempFile As String
TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
With ActiveWorkbook.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=ActiveSheet.Name, _
Source:=Selection.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
Set ts = Nothing
Set fso = Nothing
Kill TempFile
End Function