+ Reply to Thread
Results 1 to 2 of 2

Thread: Send mails

  1. #1

    Send mails

    I want to send mails using vbs , is that possible ?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    31
    Here is the code , but you need to define your smtp server
    Code:
    WScript.Echo EMail( "Fname Lname <name@example.com>", _"Fname Lname <toperson@example.com>", _"This is subject", _"this is body" & vbCrLf & "<<Line breaked", _"", _"", _"smtp.server.com", _25 )
    
     Function EMail( myFrom, myTo, mySubject, myTextBody, myHTMLBody, myAttachment, mySMTPServer, mySMTPPort )
     
         ' Standard housekeeping
         Dim i, objEmail
    
         ' Use custom error handling
         On Error Resume Next
    
         ' Create an e-mail message object
         Set objEmail = CreateObject( "CDO.Message" )
    
         ' Fill in the field values
         With objEmail
             .From     = myFrom
             .To       = myTo
             ' Other options you might want to add:
             ' .Cc     = ...
             ' .Bcc    = ...
             .Subject  = mySubject
             .Textbody = myTextBody
             .HTMLBody = myHTMLBody
             If IsArray( myAttachment ) Then
                 For i = 0 To UBound( myAttachment )
                     .AddAttachment Replace( myAttachment( i ), "\", "\\" ),"",""
                 Next
             ElseIf myAttachment <> "" Then
                 .AddAttachment Replace( myAttachment, "\", "\\" ),"",""
             End If
             If mySMTPPort = "" Then
                 mySMTPPort = 25
             End If
             With .Configuration.Fields
                 .Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"      ) = 2
                 .Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"     ) = mySMTPServer
                 .Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = mySMTPPort
                 .Update
             End With
             ' Send the message
             .Send
         End With
         ' Return status message
         If Err Then
             EMail = "ERROR " & Err.Number & ": " & Err.Description
             Err.Clear
         Else
             EMail = "Message sent ok"
         End If
    
         ' Release the e-mail message object
         Set objEmail = Nothing
         ' Restore default error handling
         On Error Goto 0
     End Function

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts