UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Error Sending Email From Access Using CDO, Access 2016    
 
   
Ub78Nx
post Oct 18 2017, 01:25 PM
Post#1



Posts: 8
Joined: 9-October 17



I have been tasked with trying to get Access to send emails. My supervisor told me he used to be able to do it with Outlook, but ever since the company switched to G suite with a custom domain he has not been able to get it to work. I did some quick research and found several code examples using CDO objects in VBA. I copied one of the examples and put it into a module then modified it to meet my needs. I have been able to get this to work using my personal Gmail account and the smtp.gmail.com server, but when I try to change it to the company information I get an error. I have confirmed that I have the right SMTP server and port for the company email. The error I get is "The server rejected the sender address. The server response was: 554 Mail from my.name@company.com rejected for policy reasons." I looked that up and it seems to be a spam related error.

My question is, is there something wrong with my code that is creating this error? It does not seem to be reading my username and password fields. If I comment them out it still gives the same error. I'm hoping that if I can get it to read those fields the server will accept the sender address and the error will go away. On the other hand, if this is something I need to have IT grant access to, does anyone know what I need changed? I spoke with the local IT guys and they didn't know, but they don't do network stuff, mostly just setting up new hardware. I'll have to talk to the corporate guys and I want to make sure I explain exactly what I need. Any advice/recommendations are appreciated.

CODE
Public Function send_email()

    Set cdomsg = CreateObject("CDO.message")
    With cdomsg.Configuration.Fields
        .Item("http://schemas.microsoft.com/CDO/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/CDO/configuration/smtpserver") = "smtp.mydomain.com"
        .Item("http://schemas.microsoft.com/CDO/configuration/smptserverport") = 25
        .Item("http://schemas.microsoft.com/CDO/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/CDO/configuration/smtpusessl") = False
        .Item("http://schemas.microsoft.com/CDO/configuration/smtpconnectiontimeout") = 60
        .Item("http://schemas.microsoft.com/CDO/configuration/sendusername") = "my.name@company.com"
        .Item("http://schemas.microsoft.com/CDO/configuration/sendpassword") = "mypassword"
        .Update
    End With
    
    ' build email parts
    With cdomsg
        .To = "my.name@company.com"
        .From = "my.name@company.com"
        .Subject = "the email subject"
        .TextBody = "the full message body goes here. you may want to create a variable to hold the text"
        .Send
    End With
        
    Set cdomsg = Nothing
End Function
Go to the top of the page
 
Ub78Nx
post Oct 20 2017, 08:58 AM
Post#2



Posts: 8
Joined: 9-October 17



Thanks for the testing utility Ridders, although it's really just created more questions. I can still send email through regular gmail with my code block, but I can't get your utility to do the same. I'm using port 587 with SSL in my code block but using those same setting in your utility I get a transport error that it can't connect to the server. I've tried changing all the different settings and using port 465 instead with no luck. I'm not sure what I'm doing wrong, and I don't think I'll be able to troubleshoot the business email issues until I can get it to work with a regular gmail address.

Here is the code I have used to send a gmail message directly from Access.

CODE
Public Function send_gmail()
    Set cdomsg = CreateObject("CDO.message")
    With cdomsg.Configuration.Fields
        .Item("http://schemas.microsoft.com/CDO/configuration/sendusing") = cdoSendUsingPort 'NTLM method
        .Item("http://schemas.microsoft.com/CDO/configuration/smtpserver") = "smtp.gmail.com"
        .Item("http://schemas.microsoft.com/CDO/configuration/smptserverport") = 587
        .Item("http://schemas.microsoft.com/CDO/configuration/smtpauthenticate") = cdoBasic
        .Item("http://schemas.microsoft.com/CDO/configuration/smtpusessl") = True
        .Item("http://schemas.microsoft.com/CDO/configuration/smtpconnectiontimeout") = 60
        .Item("http://schemas.microsoft.com/CDO/configuration/sendusername") = "me@gmail.com"
        .Item("http://schemas.microsoft.com/CDO/configuration/sendpassword") = "password"
        .Update
    End With
    
    ' build email parts
    With cdomsg
        .To = "me@work.com"
        .From = "me@gmail.com"
        .Subject = "the email subject"
        .TextBody = "the full message body goes here. you may want to create a variable to hold the text"
        .Send
    End With
        
    Set cdomsg = Nothing
End Function
Go to the top of the page
 
Ub78Nx
post Oct 23 2017, 08:35 AM
Post#3



Posts: 8
Joined: 9-October 17



Well, after all this I was finally able to get the main IT department to grant me access to the SMTP server. I can now send emails just fine.

I do have one more question and I'll ask it here before starting a new thread. How do the sendusername and sendpassword fields work? The program seems to be sending the emails based on the cdomsg.From field and ignoring the username and password fields. I've tried cdoBasic and cdoNTLM for the smtpauthenticate setting and both act the same. SSL is set to False as it won't won't connect to the server if it's set to True. I'm worried about the security issue if someone can send emails using another users account.

Thanks.

*Edit* I tried it in your email tester and it works from there now too Ritters. It has the same issue where I can enter anything into the username and password and it still sends.
Go to the top of the page
 
Ub78Nx
post Nov 8 2017, 08:54 AM
Post#4



Posts: 8
Joined: 9-October 17



Thank you for the explanation. My supervisor wanted the ability to see who was sending the emails out so we settled on creating a table of usernames and auto populating the From field based on whoever is logged into the computer. As long as users aren't sharing computers we shouldn't have any issues.

As to your question, cdoBasic and cdoNTLM are 1 and 2 respectively, cdoAnonymous is 0. Via https://msdn.microsoft.com/en-us/library/ms...=exchg.10).aspx
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    11th December 2017 - 02:49 AM