This code uses the CDO.Message method.
Code:
Option Explicit
Dim msgA As Object 'Define the CDO
Private Function GmailSend(xUsername, xPassword, xMailTo, xSubject, xMainText)
Set msgA = CreateObject("CDO.Message") 'set the CDO to reffer as.
msgA.To = xMailTo 'get targeted mail from command
msgA.Subject = xSubject 'get subject from command
msgA.HTMLBody = xMainText 'Main Text - You may use HTML tags here, for example <BR> to immitate "VBCRLF" (start new line) etc.
' HTMLBODY is a STRING, do not try to link a multilined textbox to it without using the ''replace'' function for 'VBCRLf' with '<BR>' (example later)
'Notice, i simplified it, however, you may use more values depending on your needs, such as:
'.Bcc = "mail@mail.com" ' - BCC..
'.Cc = "mail@mail.com" ' - CC..
'.From
'.CreateMHTMLBody ("www.mywebsite.com/index.html) 'send an entire webpage from a site
'.CreateMHTMLBody ("c:\program files\download.htm) 'Send an entire webpage from your PC
'.AddAttachment ("c:\myfile.zip") 'Send a file from your pc (notice uploading may take a while depending on your connection)
'Gmail Username (from which mail will be sent)
msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = xUsername
'Gmail Password
msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = xPassword
'Mail Server address.
msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
0 comments:
Post a Comment