2016-05-30 66 views
3

私は、VB6アプリケーションでOffice365 SMTPサーバーを設定する方法を探しています。私のコードは、ポート465と他のメールサーバーで正しく動作しています。 しかし、それはポート587とsmtp.office365.comで動作していませんVB6でCDO/SMTP/TLSを使用して電子メールを送信するsmtp.office365.comメールサーバー

私はVB6で587経由でTLSを持つことができる方法はありますか?我々はISPの(サーバー側で偶然変更または多分何かを)切り替えるとき

おかげ

答えて

3

このコードでは、CDOを使用してOffice365にメールを送信します。

Private Message As CDO.Message 
Private Attachment, Expression, Matches, FilenameMatch, i 

Sub enviar_mail() 

Set Message = New CDO.Message 
Message.Subject = "Test Mail" 
Message.From = "[email protected]" 
Message.To = "" 
Message.CC = "" 
Message.TextBody = "my text body here" 

Dim Configuration 
Set Configuration = CreateObject("CDO.Configuration") 
Configuration.Load -1 ' CDO Source Defaults 
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com" 
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "YourPass" 
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True 

Configuration.Fields.Update 

Set Message.Configuration = Configuration 
Message.Send 

End Subの私はポートを設定すると

0

は、このコードは、数日前までは私のために働きました。ポート587を指定すると、トランスポートエラーが発生し、VBAでその解決策が見つかりませんでした。これはあなたのために働く、あなたが587を使用する方法を見つけた場合場合は私に知らせてください(ポート25は、いずれかの私のために同じエラーが動作しません。)

Public Function SMTPSend(vSendTo, vsubject As Variant, vmessage As Variant) 
'This works 
Set emailObj = CreateObject("CDO.Message") 

emailObj.From = "[email protected]" 
emailObj.To = vSendTo 
emailObj.Subject = vsubject 
emailObj.TextBody = vmessage 
'emailObj.AddAttachment "c:\windows\win.ini" 

Set emailConfig = emailObj.configuration 


emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com" 
'Must exclude port if specifying SSL 
'emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword" 
emailConfig.Fields.Update 

emailObj.Send 

If Err.Number = 0 Then SMTPSend = True Else SMTPSend = False 

End Function 
+0

それは動作しません。 smtpserverportフィールドをオフのままにしておくと、ポート25にデフォルト設定されていると見なします。新しいISPブロック25が見つかりました。周りを見回して、CDOまたはVBAがsmtpserverportを正しく渡していないようです。誰かが秘密を知っているなら、助けを使うことができるこのような多くの投稿があります。 – pghcpa

+0

.NETライブラリは、VB6または従来のASPコードでは** **サポートしていません。 – eidylon

0

あなたが解決できれば、私は知りません

Private Sub Command1_Click() 

Dim oSmtp As New EASendMailObjLib.Mail 
oSmtp.LicenseCode = "TryIt" 

' Set your Hotmail email address 
oSmtp.FromAddr = "[email protected]" 

' Add recipient email address 
oSmtp.AddRecipientEx "[email protected]", 0 

' Set email subject 
oSmtp.Subject = "test email from hotmail account" 

' Set email body 
oSmtp.BodyText = "this is a test email sent from VB 6.0 project with hotmail" 

' Hotmail SMTP server address 
oSmtp.ServerAddr = "smtp.live.com" 

' Hotmail user authentication should use your 
' Hotmail email address as the user name. 
oSmtp.UserName = "[email protected]" 
oSmtp.Password = "yourpassword" 

' Set port to 25, if you want to use 587 port, please change 25 to 587 
oSmtp.ServerPort = 25 

' detect SSL/TLS connection automatically 
oSmtp.SSL_init 

MsgBox "start to send email ..." 

If oSmtp.SendMail() = 0 Then 
    MsgBox "email was sent successfully!" 
Else 
    MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription() 
End If 

End Subの

フォント::https://www.emailarchitect.net/easendmail/kb/vb.aspx?cat=4

ライブラリをダウンロードし忘れないでください

それが、私はこれでそれを得ました0

http://easendmail-smtp-component-net-edition.soft112.com/

ちょうどパラメータを置き換えてください!

+0

CDOが私には役に立たないので、私はこのライブラリ "easendmail"を使用しています。 ダウンロード:http://easendmail-smtp-component-net-edition.soft112.com/ –

関連する問題