Latest News
Đẩy log exception của spring boot lên elasticsearch
  • About
  • EmEditor
  • Register Google Adsense

Love Coding

Note anything I want

  • Home
  • Web Development
    • HTML
    • Javascript
    • jQuery
    • CSS
    • PHP
    • ASP
    • JSP
    • Fix Bug
  • Other Development
    • Desktop Java
    • Mobile J2ME
    • VBS
  • Operating System
    • Windows
    • Linux
  • Database
    • MySQL
    • Oracle
  • Software
Home » VBS » Love Coding: Send email with Gmail account via vbscript

Send email with Gmail account via vbscript

HuyPV
Add Comment
VBS
Sunday, April 12, 2009
'Library CDO
'D:\WINDOWS\system32\cdosys.dll
'Microsoft CDO for Windows 2000 Library

Const cdoBasic = 1 'basic (clear-text) authentication

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = """Phung Van Huy"" <codjng@gmail.com>"
objMessage.To = "huyphungvan@yahoo.com"
objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication."

'This section provides the configuration information for the remote SMTP server.
With objMessage.Configuration.Fields
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
    
    'Your UserID on the SMTP server
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "huyphungvan"
    'Your password on the SMTP server
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "***********"

    'Server port (typically 25)
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    
    'Use SSL for the connection (False or True)
    'Get error: Must issue a STARTTLS command first, if server use SSL but you set False
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    
    .Update
End With
'End remote SMTP server configuration section

On Error Resume Next
objMessage.Send
If Err <> 0 Then
    Msgbox "Send email failed: " & Err.Description
Else
    Msgbox "OK!"
End if
Tweet
Send email with Gmail account via vbscript Title: Send email with Gmail account via vbscript
Description: 'Library CDO 'D:\WINDOWS\system32\cdosys.dll 'Microsoft CDO for Windows 2000 Library Const cdoBasic = 1 'basic (clear-text) ... ...
Rating: 4

6 comments :

  1. Manos FragoulisJuly 23, 2009 at 3:31 PM

    Thnx a lot, this code have been very helpfull!

    ReplyDelete
    Replies
      Reply
  2. Yaniv CohenJuly 19, 2011 at 12:10 AM

    What about add attach
    can you advice

    ReplyDelete
    Replies
      Reply
  3. HuyPVJuly 23, 2011 at 2:27 AM

    Just add above line before call objMessage.Send:
    objMessage.AddAttachment "C:\Documents and Settings\huypv\My Documents\Downloads\huypv.gif"

    ReplyDelete
    Replies
      Reply
  4. jj09895508817August 25, 2012 at 2:57 PM

    Thank's Dear... it's working Properly....

    ReplyDelete
    Replies
      Reply
  5. Chetan PalrechaApril 8, 2013 at 12:53 PM

    It throws me this error everytime I run this script,

    The transport failed to connect to the server

    When I run it using Anonymous, the mails are stacked up in Queue folder. Can anyone help me on this?
    Also, I'm connecting to internet using Proxy does that matter?

    ReplyDelete
    Replies
      Reply
  6. HuyPVApril 8, 2013 at 3:28 PM

    You have to add proxy config info to source code.

    .Item("http://schemas.microsoft.com/cdo/configuration/urlproxyserver") = "127.0.0.1:3128"
    .Item("http://schemas.microsoft.com/cdo/configuration/urlproxybypass") = "<local>"

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

Newer Post Older Post Home
Subscribe to: Post Comments ( Atom )
Quảng cáo

Popular Posts

  • VBS - Upload file HTTP Post
    Source: http://www.ericphelps.com/scripting/samples/Reference/Web/HTTP_POST.txt   Sub Upload(strUploadUrl, strFilePath, strFileField, strD...
  • Add other collapse div to your forum
    Collapse <div style="height: 16px; padding-right: 4px; font-weight: bold;" class="blockhead"> <span style=...
  • Use the YouTube API with PHP
    Process and integrate data from YouTube into your PHP application with PHP's SimpleXML extension Summary:   The YouTube vide...
  • Check Laravel version
    Đối tác bảo đang code và dùng Laravel, giờ muốn biết version Laravel tương ứng là bao nhiêu để xem mà code theo. Làm sao check? Cách 1: Sử...
  • Hàm chuyển từ ngày dương lịch sang âm lịch (PHP)
    <?php function INT($d) {     return floor($d); } function jdFromDate($dd, $mm, $yy) {     $a = INT((14 - $mm) / 12);     $y = $yy + 4800 ...
  • Character Set và Collation trong MySQL là gì? Tạo DB thì để UTF8_GENERAL_CI hay UTF8_BIN
    Character Set là một tập các ký tự và dạng số hóa của các ký tự đó Collation là một tập các luật để so sánh các xâu được sinh ra từ các ký ...
  • Trong laravel thì queue:work với queue:listen khác nhau thế nào?
    Trong laravel thì queue:work với queue:listen đều chạy jobs trong queue. Vậy 2 cái này cũng phải có gì đó khác nhau chứ, nếu ko thì nó là ...
  • mysql_error: Undeclared variable: INF
    mysql_error: Undeclared variable: INF PHP Code: $limit = 10; $page = isset($_GET['p']) ? $_GET['p'] : 1; $offset = ($pa...
  • git checkout file from other branch
    Đang làm trên nhánh dev. Muốn lấy 1 file, ví dụ: xxx/helper.php ở trên nhánh master về dev thì làm thế nào? Cách 1: nông dân nhiều bước nh...
  • Download media files (video, audio) from VnExpress.Net
    Download media files (video, audio) from VnExpress.Net Example: http://vnexpress.net/GL/Vi-tinh/Giai-tri/2010/02/3BA18A0E/page_4.asp htt...
Back to top!
Copyright 2010 Love Coding - All Rights Reserved Design by Newbie_PC - Powered by Blogger