{"id":82,"date":"2008-08-07T14:34:38","date_gmt":"2008-08-07T18:34:38","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/2008\/08\/07\/sending-emails-using-vbscript\/"},"modified":"2008-08-07T14:34:38","modified_gmt":"2008-08-07T18:34:38","slug":"sending-emails-using-vbscript","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2008\/08\/07\/sending-emails-using-vbscript\/","title":{"rendered":"Sending emails using VBScript"},"content":{"rendered":"<p>To do so, follow the sample code shown below.  To use the code as-is, just alter the configuration parameters by providing the from address, to address, subject, body, and SMTP server information.  Optionally, you may also provide a path to a file that you want to attach to the email.  Usually SMTP port number is 25; if you are unsure, leave this parameter untouched and it will probably work at the default value of 25.<\/p>\n<pre class=\"code\">\noption explicit\n\ndim fromAddress, toAddress, subj, body, smtp, attach, smtpPort\n\n'''''''''''''''''\n' Configuration '\n'''''''''''''''''\n\n' Required parameters\nfromAddress = \"my@email.address\"      ' The from email address\ntoAddress = \"recepient@email.address\" ' The to email address\nsubj = \"Email Subject\"                ' The subject of the email\nbody = \"Put a message here!\"          ' The body message of the email\nsmtp = \"mail.server.com\"              ' Name of the SMTP server you wish to use\n\n' Optional parameters\nattach = \"c:filename.txt\"            ' Optional file you may wish to attach to the email\nsmtpPort = 25                         ' SMTP port used by your server, usually 25; if not provided, the script will default to 25\n\n'''''''''''''''''''''\n' End Configuration '\n'''''''''''''''''''''\n\n\nif fromAddress = \"\" then\n\tmsgbox(\"Error: From email address not defined\")\nelseif toAddress = \"\" then\n\tmsgbox(\"Error: To email address not defined\")\nelseif subj = \"\" then\n\tmsgbox(\"Error: Subject not defined\")\nelseif body = \"\" then\n\tmsgbox(\"Error: Body not defined\")\nelseif smtp = \"\" then\n\tmsgbox(\"Error: SMTP server not defined\")\nelse\n\tdim objMessage\n\tSet objMessage = CreateObject(\"CDO.Message\")\n\tobjMessage.Subject = subj\n\tobjMessage.From = fromAddress\n\tobjMessage.To = toAddress\n\tobjMessage.TextBody = body\n\tif attach <> \"\" then\n\t\tobjMessage.AddAttachment attach\n\tend if\n\t\n\tobjMessage.Configuration.Fields.Item (\"http:\/\/schemas.microsoft.com\/cdo\/configuration\/sendusing\") = 2\n\tobjMessage.Configuration.Fields.Item (\"http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserver\") = smtp\n\tif smtpPort <> \"\" then\n\t\tobjMessage.Configuration.Fields.Item (\"http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserverport\") = smtpPort\n\telse\n\t\tobjMessage.Configuration.Fields.Item (\"http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserverport\") = 25\n\tend if\n\tobjMessage.Configuration.Fields.Update\n\t\n\tobjMessage.Send\n\t\n\tmsgbox(\"Email sent successfully\")\nend if\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sample code provided in this article demonstrates how you can send an email, optionally with an attachment, using VBScript.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-82","post","type-post","status-publish","format-standard","hentry","category-vbscript"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/82","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":0,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}