Send Email as NoReply@mycompany.com (1 Viewer)

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 16:05
Joined
Oct 17, 2012
Messages
3,276
For an invoicing tie-in application my company has me building, I need to email invoices out to our vendors. I have that part working fine, but right now in order to get it to use our NoReply email, I have to have the program use the .SentOnBehalfOfName method.

What I'd like to do is have it just send the emails (with an attachement) directly through the NoReply instead, so that I don't have to wait on IT to authorize a new user to send on behalf. However, I have no idea how to do that. The Outlook automation info I found says you can't do that directly.

I did find info on the NameSpace.Logon method, but that doesn't seem to allow you to put in a username. Is there some OTHER way to do this that I'm missing?
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 16:05
Joined
Oct 17, 2012
Messages
3,276
Aaaand had I spent about 5 more minutes looking, I'd have figured it out. :banghead:

Well, next question: How would i go about encrypting (and afterward, accessing) the password that I'll need to use in the code?
 

spikepl

Eledittingent Beliped
Local time
Today, 22:05
Joined
Nov 3, 2010
Messages
6,142
I am sure that future readers of this post will be ecstatic that you have found a solution to your problem, but perhaps rather less than ecstatic that you kept the solution to yourself, thereby rendering this entire thread utterly pointless for anyone else. :D

The entire forum is a joint effort of all contributors meant to benefit not only current but also future users.
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 16:05
Joined
Oct 17, 2012
Messages
3,276
Lol fair point, I didn't post it just because it was pretty much a straight copy paste from elsewhere, and it currently has my login and password hardcoded in it while I test. After chopping out identifying info, here you go.

Code:
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Const cdoAnonymous = 0
' Use basic (clear-text) authentication.
Const cdoBasic = 1
' Use NTLM authentication
Const cdoNTLM = 2 'NTLM

Public Sub SendEmail(ByRef strTo As String, _
                     ByRef strFrom As String, _
                     ByRef strSubject As String, _
                     ByRef strBody As String, _
                     ByRef strReplyTo As String, _
                     ByRef strSender As String, _
                     Optional ByRef strAttachmentPath As String)
                     
Dim imsg As Object
Dim iconf As Object
Dim flds As Object
Dim schema As String
Dim strProcName As String
    
    On Error GoTo SendEmail_Err
    
    strProcName = "SendEmail"

    Set imsg = CreateObject("CDO.Message")
    Set iconf = CreateObject("CDO.Configuration")
    Set flds = iconf.Fields

    ' send one copy with SMTP server (with autentication)
    schema = "http://schemas.microsoft.com/cdo/configuration/"
    flds.Item(schema & "sendusing") = cdoSendUsingPort
    flds.Item(schema & "smtpserver") = "mail.<server>.com"
    flds.Item(schema & "smtpserverport") = 25
    flds.Item(schema & "smtpauthenticate") = cdoBasic
    flds.Item(schema & "sendusername") = "<My login>"
    flds.Item(schema & "sendpassword") = "<My password>"
    flds.Item(schema & "smtpusessl") = False
    flds.Update

    With imsg
        .To = strTo
        .From = strFrom
        .Subject = strSubject
        .HTMLBody = strBody
        .Sender = strSender
        .Organization = <Company Name>
        .ReplyTo = strReplyTo
        If strAttachmentPath <> "" Then .AddAttachment strAttachmentPath
        Set .Configuration = iconf
        .Send
    End With
    
    Set iconf = Nothing
    Set imsg = Nothing
    Set flds = Nothing
    
SendEmail_Exit:
    Exit Sub

SendEmail_Err:
        
    MsgBox "Error occurred" & vbCrLf & vbCrLf & _
    "In Function:" & vbTab & strProcName & vbCrLf & _
    "Err Number: " & vbTab & Err.Number & vbCrLf & _
    "Description: " & vbTab & Err.Description, vbCritical, _
    "Error in " & Chr$(34) & strProcName & Chr$(34)
    Resume SendEmail_Exit

End Sub

So, with that done, any suggestions on how to encrypt that password?
 

Users who are viewing this thread

Top Bottom