Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use vbs to send mail with attachments

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use vbs to send attached e-mail, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

Function Send_mail (You_Account,You_Password,Send_Email,Send_Email2,Send_Topic,Send_Body,Send_Attachment)

'code by NetPatch

'description of parameters for VBS to send email

You_Account: your email account

You_Password: your email password

'Send_Email: primary email address

'Send_Email2: alternate email address

Send_Topic: the subject of the message

'Send_Body: the content of the message

'Send_Attachment: email attachment

You_ID=Split (You_Account, @,-1, vbTextCompare)

'The account is separated from the server

MS_Space = "http://schemas.microsoft.com/cdo/configuration/"

This is a must, but you can rest assured that e-mail will not be sent through Microsoft

Set Email = CreateObject ("CDO.Message")

Email.From = You_Account

This must be the same as the account that sent the mail

Email.To = Send_Email 'primary email address

If Send_Email2 "" Then

Email.CC = Send_Email2 'alternate email address

End If

Email.Subject = Send_Topic 'email subject

Email.Textbody = Send_Body 'message content

If Send_Attachment "" Then

Email.AddAttachment Send_Attachment 'email attachment

End If

With Email.Configuration.Fields

.Item (MS_Space& "sendusing") = 2 'outgoing port

.Item (MS_Space& "smtpserver") = "smtp." & You_ID (1) 'SMTP server address

.Item (MS_Space& "smtpserverport") = 25 'SMTP server port

.Item (MS_Space& "smtpauthenticate") = 1 'cdobasec

.Item (MS_Space& "sendusername") = You_ID (0) 'your email account

.Item (MS_Space& "sendpassword") = You_Password 'your email password

.Update

End With

Email.Send

'send an email

Set Email=Nothing

'close the component

Send_Mail=True

If there is no error message, it means it was sent successfully, otherwise it failed.

If Err Then

Err.Clear

Send_Mail=False

End If

End Function

The following is an example of sending an email with an attachment using the function above

If Send_Mail ("test@163.com", "test", "test2@163.com", "", "message subject", "message content", "d:\ test.exe") = True Then

Wscript.Echo "sent successfully"

Else

Wscript.Echo "send failed"

End If

Thank you for reading this article carefully. I hope the article "how to send an attached email with vbs" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report