Link to home
Start Free TrialLog in
Avatar of dawber39
dawber39Flag for United States of America

asked on

VBSendMail

Hi,

I am using the VBSendMail in MS Access from within another Access application. When the sendmail is implemented, it appears the connection times out. I look at my settings in Outlook and it appears that my outgoing server requires authentication, so I am wondering if anyone knows where I would add the username and password to the code and to the MyMail table, so I can add it to the form. The code being used now - is below

Option Compare Database
Option Explicit

Private WithEvents poSendMail As MyMail.clsSendMail
' Reference to c:\windows\system\MyMail.OCX
'
Private Sub btnSend_Click()
    btnSend.Caption = "Sending"
    Set poSendMail = New MyMail.clsSendMail
    With poSendMail
        .SMTPHost = Form!txtServer             ' Required the fist time, optional thereafter
        .From = Form!txtFrom                        ' Required the fist time, optional thereafter
        .FromDisplayName = Form!txtFromName         ' Optional, saved after first use
        .Message = "<HTML><BODY>" & Form!txtMsg & "</BODY></HTML>"
        .AsHTML = True ' Optional
        .Recipient = Form!txtTo
        .CcRecipient = Form!txtCC
        .RecipientDisplayName = Form!txtToName
        .Subject = Form!txtSubject
        .Attachment = Text20 & ";" & Text22 & ";" & Text24
        .RequestReceipt = Form!cbRequestReadReceipt
        .Send
    End With
    DoCmd.Quit
End Sub
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

I suggest using CDO. See http://www.rondebruin.nl/win/s1/cdo.htm and http://www.cpearson.com/excel/Email.aspx
While those links are for Excel the idea is the same in Access.
Avatar of dawber39

ASKER

While I appreciate the CDO suggestion, I do not see the ability to add multiple attachments to a single receiver, and the VBSendMail allows multiple recipients, I did not see that in the multiple instances I researched. The VBSendMail can have Pop3 authentication added to it, and I am looking for how to do that. The CDO would require rewriting or amending multiple modules, whereas the SendMail I can just add two lines of code. But thank you for the suggestion.
I f you insist. Add the following lines within your with block.
'SMTP Authentication
.UseAuthentication = True
.Username = EmailUserName
.Password = EmailPassword

Open in new window

I will try and work with this. I did try it just as you have it here using the actual username, and password - but I see I have to declare the variables. I also tried it with pulling the info from text boxes as .text like below- and as .value. But it still fails to connect. Firewall is off, and so is anti-virus. Maybe I am putting it in the wrong place?, I am locating these lines directly after the outgoing server name.

'SMTP Authentication
.UseAuthentication = True
.Username = Text29.text
.Password = Text31.text
You don't have to use variables, you can use the info entered in text-boxes just erase the .Text after the text-boxes name.

btw, is the name of your form "Form"?
The form name is "frmSendMail"
SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I appreciate the offer LukeChung-FMS  -but although I do not have this working yet, a few lines of code is more feasible than purchasing an entirely separate application. I can also use outlook in an automated process to send the email, but the VBSendMail is fast, small, and much less complicated in the automation. Thank you for your input though - it is appreciated.
I still don't have it working, but I will get it going eventually.
Then why close the question?
Because, it makes more sense for me to try and figure out what is wrong with it, rather than me wasting your time, and have you keep re-posting. I will repost the question - if I cannot figure it out. Thank you for your time, I am sure there is something I am overlooking. I have the application working in another state - through another email server with the same company (Comcast), however - their is no authentication required there, which is surprising. Surprising because  - although the company has Comcast Business Class internet, they do not have Comcast email accounts, but they are using the Comcast email server
Thank you Mr. Dettman, I appreciate that, and I can understand your perspective on my closing the question. Thanks again, and I apologize for any inconvenience.
<<Thanks again, and I apologize for any inconvenience. >>

 Really wasn't any; couple of clicks at best<g>

 So let's see about getting this nailed...are you still having problems?

Jim.
I am still having issues, I am back to work on it today - so I will update soon.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I managed to get the correct port added to the code, Then I was getting an Authentication required error. That is further than I got before - I then added the code from macroshadow, added the appropriate text boxes - and Voila - she is a working. Thank you Jim for putting me on the right track with the port parameters, and so forth..
Awesome as always!! Thanks people!!
Just for everyone else - the top lines of code should be:

        .SMTPPort = 587 'or whatever port number your email provider uses for outgoing
        .SMTPHost = Form!txtServer            
        .UseAuthentication = True
        .Username = Forms!frmSendMail!Text29
        .Password = Forms!frmSendMail!Text31