fortypoundhead.com

dwirch

Joined:
2005-01-01
08:24

Last Seen:
2017-08-20
15:54

Posted on:
2013-05-22
07:12

Sending mail with VB6

Report Back to Forum Back to All Forums

Dean Dusenbery wrote a most excellent piece of code called vbSendMail, which works very well. Sometimes though, you may want to provide mail functionality without the reliance on a DLL file. Hence the below code, which allows you to send mail from within your program, without the need for external code. Sub sendmail() Dim iMsg As Object Dim iConf As Object Dim Flds As Variant Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") iConf.Load -1 ' CDO Source Defaults Set Flds = iConf.Fields With Flds .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "yourmail@gmail.com" .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpasswordhere" .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Update End With strbody = "Your Sample message " With iMsg Set .Configuration = iConf .To = sendto .CC = "" .BCC = "" ' Note: The reply address is not working if you use this Gmail example ' It will use your Gmail address automatic. But you can add this line ' to change the reply address .ReplyTo = "Reply@something.com" .From = "" .Subject = "subject here" .TextBody = strbody .Send End With End Sub

uhlberg

Joined:
2013-09-05
03:41

Last Seen:
2013-09-08
09:15

Posted on:
2013-09-05
23:52

Report Back to Forum Back to All Forums

Works really great. Thank you!

Do you have an idea how to attach a file to ?

uhlberg

Joined:
2013-09-05
03:41

Last Seen:
2013-09-08
09:15

Posted on:
2013-09-08
09:15

Report Back to Forum Back to All Forums

Sorry, I found the code above in http://www.paulsadowski.com/wsh/cdo.htm

By repeating the AddAttachment method you can attach more than one file.

.AddAttachment "c:\temp\readme.txt"

You must be logged in order to post a reply.



Recent Forum Posts

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers

New security implemented
dwirch posted on August 8, 2017 at about 6:43 in Site News

New security implemented
dwirch posted on July 23, 2017 at about 6:58 in Site News

Fold Code Manager into main KB?
VB6Boy posted on July 22, 2017 at about 14:42 in Site News

Fold Code Manager into main KB?
dwirch posted on July 22, 2017 at about 14:41 in Site News