Looking for mailing solution - email

I'm using ASP code and AspEmail component to send emails to our clinets, but I have some problmes...
I have more then 1000 email address that I need to send them an email, becuase of my SMTP provider limitation, I can't add them all as BCC in one email but I need to send each email seperatly, therefor looping on +1000 times witch takes forever and fires the server timeout error.
I need to send those emails about 20 times a day.
This is my script:
on error resume next
msg = "SOME TEXT HERE"
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "SMPT.HOST.ADDRESS"
Mail.Port = 25
Mail.CharSet = "UTF-8"
Mail.ContentTransferEncoding = "Quoted-Printable"
Mail.From = "noreply#mydomain.co.il"
MailSubject = "email subject"
Mail.Subject = Mail.EncodeHeader(MailSubject, "utf-8")
Mail.Body = msg
Mail.IsHTML = True
zBcc = split(zBcc, ";") '1000 emails here
for i=0 to Ubound(zBcc)
zBcc(i) = trim(zBcc(i))
if len(zBcc(i))>0 then
if inStr(zBcc(i), " ")>0 then
else
if (Mail.ValidateAddress(zBcc(i)) = 0) then
Mail.Reset()
Mail.AddAddress zBcc(i)
Mail.Send
end if
end if
end if
next
set Mail=nothing

why dont you do it using a pagination type logic i.e.
limit by 100,
loop thru that batch,
once that has completed,
reload the page with the next offset in mind like send-email.asp?offset=100, send-email.asp?offset=200, etc.
use that offset value to get next batch
repeat process until end of recordset.
At least you have less chance of it timing out altho you can increase it: server.ScriptTimeout = 180

First of all I'd maximize the number of BCC's per cycle. Let's say you can email 50 BCC's in one go; you should: especially when you need this page about 20 times a day.
Anyway. Before you start; maximize the scripttimeout
Server.ScriptTimeout = 2147483647

Related

NodeMCU SMTP Email

I'm working with NodeMCU (docs here http://nodemcu.readthedocs.io/) trying to send an email through SMTP. I got this script off the net and everything seems to be working okay as there are no errors but I don't see any emails in my box, so something must be going wrong. Using the display function as the send callback prints nil unfortunately.
I was able to send smtp email through simple curl so I know that google will accept smtp requests through command line and these settings are correct. Also according to this thread it is possible, they are doing the same thing sending raw strings to gmail's smtp service (http://www.esp8266.com/viewtopic.php?f=24&t=1231&start=8).
-- The email and password from the account you want to send emails from
MY_EMAIL = "REDACTED"
EMAIL_PASSWORD = "REDACTED"
-- The SMTP server and port of your email provider.
-- If you don't know it google [my email provider] SMTP settings
SMTP_SERVER = "smtp.gmail.com"
SMTP_PORT = "465"
-- The account you want to send email to
mail_to = "REDACTED"
-- Your access point's SSID and password
SSID = "REDACTED"
SSID_PASSWORD = "REDACTED"
-- configure ESP as a station
wifi.setmode(wifi.STATION)
wifi.sta.config(SSID,SSID_PASSWORD)
wifi.sta.autoconnect(1)
email_subject = ""
email_body = ""
count = 0
local smtp_socket = nil -- will be used as socket to email server
-- The display() function will be used to print the SMTP server's response
function display(sck,response)
print(response)
end
-- The do_next() function is used to send the SMTP commands to the SMTP server in the required sequence.
-- I was going to use socket callbacks but the code would not run callbacks after the first 3.
function do_next()
if(count == 0)then
count = count+1
IP_ADDRESS = wifi.sta.getip()
smtp_socket:send("HELO "..IP_ADDRESS.."\r\n")
elseif(count==1) then
count = count+1
smtp_socket:send("AUTH LOGIN\r\n")
elseif(count == 2) then
count = count + 1
smtp_socket:send("REDACTED".."\r\n")
elseif(count == 3) then
count = count + 1
smtp_socket:send("REDACTED".."\r\n")
elseif(count==4) then
count = count+1
smtp_socket:send("MAIL FROM:<" .. MY_EMAIL .. ">\r\n")
elseif(count==5) then
count = count+1
smtp_socket:send("RCPT TO:<" .. mail_to ..">\r\n")
elseif(count==6) then
count = count+1
smtp_socket:send("DATA\r\n")
elseif(count==7) then
count = count+1
local message = string.gsub(
"From: \"".. MY_EMAIL .."\"<"..MY_EMAIL..">\r\n" ..
"To: \"".. mail_to .. "\"<".. mail_to..">\r\n"..
"Subject: ".. email_subject .. "\r\n\r\n" ..
email_body,"\r\n.\r\n","")
smtp_socket:send(message.."\r\n.\r\n")
elseif(count==8) then
count = count+1
tmr.stop(0)
smtp_socket:send("QUIT\r\n")
print("msg sent")
else
smtp_socket:close()
end
print(count)
end
-- The connectted() function is executed when the SMTP socket is connected to the SMTP server.
-- This function will create a timer to call the do_next function which will send the SMTP commands
-- in sequence, one by one, every 5000 seconds.
-- You can change the time to be smaller if that works for you, I used 5000ms just because.
function connected(sck)
tmr.alarm(0,5000,1,do_next)
end
-- #name send_email
-- #description Will initiated a socket connection to the SMTP server and trigger the connected() function
-- #param subject The email's subject
-- #param body The email's body
function send_email(subject,body)
count = 0
email_subject = subject
email_body = body
smtp_socket = net.createConnection(net.TCP,0)
smtp_socket:on("connection",connected)
smtp_socket:on("receive",display)
smtp_socket:connect(SMTP_PORT, SMTP_SERVER)
end
-- Send an email
send_email("ESP8266", "[[Hi, How are your IoT projects coming along? Best Wishes,ESP8266]]")
I am available to answer questions regarding this.
A couple of points:
The old example from esp8266.com you mentioned uses consecutive socket:send calls which doesn't work anymore in recent firmwares, see http://nodemcu.readthedocs.io/en/dev/en/modules/net/#netsocketsend. It was a "bug" in the SDK this ever worked.
SMTP port 465 usually implies SSL/TLS connections. You need a firmware that supports that. Otherwise use port 25.
There's an example right in the NodeMCU repo at https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/email/send_email_smtp.lua
I assume you did replace the placeholder at do_next count 2/3 with the base64 encoded username and password? Contrary to the example script which requires a Lua encoder module you may want to use the corresponding NodeMCU module, see http://nodemcu.readthedocs.io/en/dev/en/modules/encoder/#encodertobase64.
I took your script, a recent NodeMCU firmware, changed port to 25, added base64 encode user/pw and was able to successfully deliver an email to myself.
Update 2016-07-05
Full script including WiFi init.
MY_EMAIL = "myself#my-TLD.com"
MY_EMAIL_B64 = "base64-encoded-email"
EMAIL_PASSWORD_B64 = "base64-encoded-password"
SMTP_SERVER = "my-ISPs-server"
SMTP_PORT = 25
mail_to = "myself#my-TLD.com"
email_subject = ""
email_body = ""
count = 0
smtp_socket = nil
function display(sck,response)
print(response)
end
function do_next()
if(count == 0)then
count = count+1
local IP_ADDRESS = wifi.sta.getip()
smtp_socket:send("HELO "..IP_ADDRESS.."\r\n")
elseif(count==1) then
count = count+1
smtp_socket:send("AUTH LOGIN\r\n")
elseif(count == 2) then
count = count + 1
smtp_socket:send(MY_EMAIL_B64.."\r\n")
elseif(count == 3) then
count = count + 1
smtp_socket:send(EMAIL_PASSWORD_B64.."\r\n")
elseif(count==4) then
count = count+1
smtp_socket:send("MAIL FROM:<" .. MY_EMAIL .. ">\r\n")
elseif(count==5) then
count = count+1
smtp_socket:send("RCPT TO:<" .. mail_to ..">\r\n")
elseif(count==6) then
count = count+1
smtp_socket:send("DATA\r\n")
elseif(count==7) then
count = count+1
local message = string.gsub(
"From: \"".. MY_EMAIL .."\"<"..MY_EMAIL..">\r\n" ..
"To: \"".. mail_to .. "\"<".. mail_to..">\r\n"..
"Subject: ".. email_subject .. "\r\n\r\n" ..
email_body,"\r\n.\r\n","")
smtp_socket:send(message.."\r\n.\r\n")
elseif(count==8) then
count = count+1
tmr.stop(0)
smtp_socket:send("QUIT\r\n")
else
smtp_socket:close()
end
end
function connected(sck)
tmr.alarm(0,3000,1,do_next)
end
function send_email(subject,body)
count = 0
email_subject = subject
email_body = body
smtp_socket = net.createConnection(net.TCP,0)
smtp_socket:on("connection",connected)
smtp_socket:on("receive",display)
smtp_socket:connect(SMTP_PORT,SMTP_SERVER)
end
SSID = "my-SSID"
SSID_PASSWORD = "my-WiFi-password"
wifi.setmode(wifi.STATION)
wifi.sta.config(SSID,SSID_PASSWORD)
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
send_email(
"ESP8266",
[[Hi,
How are your IoT projects coming along?
Best Wishes,
ESP8266]])
end
end)

VBScript Outlook encounters encrypted email producing error 'Entrust Entelligence Security Provider'

I have an HTA and using VBScript to loop through Outlook email folders and get folder size. The HTA is run on a shared drive by staff, it is not an administrator tool. On occasion, my company will send encrypted emails. When the VBS hits one of these emails, the following happens:
1) VBS pauses.
2) Outlook displays the 'Entrust Entelligence Security Provider' error and asks the user to click 'OK'.
3) Once OK is clicked, the VBS continues.
The Outlook message does not bring focus to Outlook, so it is possible the user will not notice the message and continue to wait for the VBS to finish.
Is there any way of avoiding this message?
Here is my code:
public TotalSize
Sub OutlookDetail
TotalSize = 0
msgbox "Depending on the size of your Outlook account, this process may take up to 60 seconds" & vbcrlf & vbcrlf & _
"If you have encrypted emails, Outlook will make a sound and give you the 'Entrust Entelligence Security Provider' message. Click 'OK' to proceed."
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Set colItems = objFolder.Items
For Each objItem in colItems
'THE OUTLOOK ERROR MAY OCCUR HERE
TotalSize = TotalSize + objItem.Size
Next
Set objInbox = objNamespace.GetDefaultFolder(olFolderInbox)
GetSubfolders(objInbox)
msgbox "The size of Inbox and all Subfolders: " & Round((TotalSize / 1048576),2) & " MB"
End Sub
Sub GetSubfolders(objParentFolder)
Set colFolders = objParentFolder.Folders
For Each objFolder in colFolders
Set objSubfolder = objParentFolder.Folders(objFolder.Name)
intSize = 0
Set colItems = objSubfolder.Items
For Each objItem in colItems
'THE OUTLOOK ERROR MAY ALSO OCCUR HERE
intSize = intSize + objItem.size
next
TotalSize = TotalSize + intSize
GetSubfolders objSubfolder
Next
End Sub

Using VBScript, how do I update Microsoft Outlook Inbox folder before accessing it in VBS?

The following is a VBScript (VBS) that I use the check for and process certain Outlook emails and attachments. The script finds the emails via their email address and subject. It then saves the attachment in a folder and moves the email to a folder within Outlook. (Most of this code was adapted from a stackoverflow.com post, but I have since forgotten which one.)
My issue: Sometimes this script has to be run before the user has opened Outlook for the day; therefore, none of the Outlook folders have been updated and the script can't find emails that have been sent to the user since the user shut Outlook down last.
My question: How do I update the Outlook inbox then proceed with the rest of the script ensuring that the Inbox is (or all Outlook folders are) completely updated? I'm not sure if VBS will wait for the folder update to happen, but if it won't, I, of course, need it to. I don't know how to update the inbox or wait for it to update if waiting is applicable.
Other tips on how to make the script better are welcome.
My VBScript:
Const olFolderInbox = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
Call SaveAndMoveAttachment("'subject 1'", objFolder)
Call SaveAndMoveAttachment("'subject 2'", objFolder)
Call SaveAndMoveAttachment("'subject 3'", objFolder)
Set objFSO = Nothing
Set objOutlook = Nothing
Set objNamespace = Nothing
WScript.Quit
Sub SaveAndMoveAttachment(sSubject, objFolder)
Set colItems = objFolder.Items
Set colFilteredItems = colItems.Restrict("[Subject] = " & sSubject)
If colFilteredItems.count = 0 then
Msgbox "An email with subject " & sSubject & " in it was not found in your Outlook Inbox"
WScript.Quit
end if
For Each objMessage In colFilteredItems
Set colAttachments = objMessage.Attachments
intCount = colAttachments.Count
If intCount <> 0 and objMessage.Sender.Address = "support#somesite.com" Then
For i = 1 To intCount
strFileName = "Z:\somepath\" & objMessage.Attachments.Item(i).FileName
objMessage.Attachments.Item(i).SaveAsFile strFileName
'move the message to somefolder folder
Set objFoldersomefolder = objNamespace.GetDefaultFolder(olFolderInbox).Folders("somefolder")
objMessage.Move objFoldersomefolder
Next
End If
Next
Set colFilteredItems = Nothing
Set colAttachments = Nothing
Set colItems = Nothing
End Sub
Add logon step between above 2 lines
WSCript.Sleep 2000
objNamespace.Logon
objNamespace.SendAndReceive(True)
Below this line:
Set objNamespace = objOutlook.GetNamespace("MAPI")
Add this:
WSCript.Sleep 2000
objNamespace.SendAndReceive(True)
I found it here:
http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_28215854.html

VB6 RS232 not receiving full data from device using MSCOMM Controll

I have a clinical device that sends data on com port, I want to receive data from device
it also received First Frame (254) character after send ACK on ENQ
it receive [ETB] [CR][LF] characters
then I again send ACK for next frame, but not receive data
only receiving EOT char
Device Communication as per device is:
<-[ENQ]
->[ACK]
<-[STX]1H|**********************-[ETB]21[CR][LF]
->[ACK]
<-[STX]1H|**********************-[ETX]8E[CR][LF]
->[ACK]
<-[EOT]
my code is:
'MSComm1.Settings = "9600,n,8,1"
'MSComm1.InputLen = 1
Private Sub MSComm1_OnComm()
Dim InBuff As String
InBuff = MSComm1.Input
if Chr$(5)=InBuff then 'ENQ received
MSComm1.Output=Chr$(6) & VbCr
elseif Chr$(10)=InBuff then 'LF received
MSComm1.Output=Chr$(6) & VbCr
else
text1.text=text1.text & InBuff
end if
End Sub
Device sending full data because 1 software comes with device which receive full data as
but I didn't receive next frame after send ACK again,
if any one have idea what output have to send FOR next ACK, please advice me
thanks in advance
Do something like this...
MSComm1.InputLen = 1 ' for sending single character from device
MSComm1.RThreshold = 1 ' for firing events on receiving a single character
Dim InBuff As String
if MSComm1.CommEvent = comEvReceive then
do
InBuff = MSComm1.Input
Loop Until MSComm1.InBufferCount < 1
Firstly receive all the data and after that use that in your own way.

CDO.Message .Send causes script execution timeout

I have the following code:
Set myMailanon = CreateObject("CDO.Message")
myMailanon.MimeFormatted = True
Set myConfanon = Server.CreateObject("CDO.Configuration")
Set objBPanon = myMailanon.AddRelatedBodyPart("http://www.foo.bar/img/logo1.jpg", "http://www.foo.bar/img/logo1.jpg", CdoReferenceTypeName)
objBPanon.Fields.Item("urn:schemas:mailheader:Content-ID") = "<http://www.foo.bar/img/logo1.jpg>"
objBPanon.Fields.Update
ConfURLanon = "http://schemas.microsoft.com/cdo/configuration/"
with myConfanon
.Fields.Item(ConfURLanon & "sendusing") = 2
.Fields.Item(ConfURLanon & "smtpserver") = "smtp.foo.bar"
.Fields.Item(ConfURLanon & "smtpserverport") = 25
.Fields.Item(ConfURLanon & "smtpusessl") = false
.Fields.Item(ConfURLanon & "smtpauthenticate") = 1
.Fields.Item(ConfURLanon & "sendusername") = "foo#bar.com"
.Fields.Item(ConfURLanon & "sendpassword") = "foobarpass"
.Fields.Update
end with
with myMailanon
.Subject='Foo!! Bar!!'
.From='Foo!! Bar!! <foo#bar.com>'
.To='foo#bar.com,bar#foo.com'
txt="This is foo... bar... text... SPARTAAAAAAAAA"
.HTMLBody = txt
Set .Configuration = myConfanon
On Error Resume Next
.Send
end with
Problem is that this code, run 100 times, will work 30 and fail 70. Randomly.
And by "fail" I mean that it will cause Script execution timeout.
After commenting line by line, I got to the conclusion that the error comes from ".Send".
But why? Any ideas?
Regards
There isn't anything wrong with code (athough CdoReferenceTypeName looks a little suspect but that could be just poor variable naming). It could just be that the SMTP server is busy and is therefore taking a while to process the send.
You could check the Script Time-out value specified for the ASP feature in IIS manager. By default it should be 90 seconds but perhaps its been set to a low value for some reason.
You can increase the amount of time you script has by specifying it in your code.
Server.ScriptTimeout = 300
Which would give your script a 5 minutes. This may well be masking some set up problem between your web server and SMTP server but it may increase the success rate. OTH you may get the same results but the 70% failures take longer to occur.
Whatever the cause I don't think its your code.