Email sending instance

Source: Internet
Author: User

email sending instance:

Private sub Sendmail () </P> <p> dim mailsender as smtpclient 'email sending object instance <br/> dim mailmsg as mailmessage 'email information instance <br/> dim mailfile as attachment' attachment instance <br/> dim mailaddressfrom as string 'sender's email address <br/> dim mailpassword as string 'email password <br/> dim mailtitle as string' email title <br/> dim mailcontent string 'mail content <br/> dim mailaddressto as string' recipient's email address </P> <p> 'variable initialization <br/> mailaddressfrom = "From@163.com"' sender's email address <br/> mailpassword = "password" 'mailbox password <br/> mailtitle = "title" 'mail title <br/> mailcontent = "test"' mail content <br/> mailaddressto = "To@163.com" 'recipient email address </P> <p> try </P> <p> 'initialize the mail Information instance <br/> mailmsg = new mailmessage (_ <br /> New mailaddress (mailaddressfrom ), _ <br/> New mailaddress (mailaddressto) </P> <p> 'sets the mail title and content. <br/> mailmsg. subject = mailtitle <br/> mailmsg. body = mailcontent </P> <p> 'add an attachment <br/> mailfile = new attachment ("C:/boot. ini ") <br/> mailmsg. attachments. add (mailfile) </P> <p> 'initialize the email sending object instance <br/> mailsender = new smtpclient () </P> <p> 'set email parameters <br/> mailsender. port = 25' port <br/> mailsender. host = "smtp.163.com" 'smtp address <br/> mailsender. deliverymethod = smtpdeliverymethod. network 'sending method <br/> mailsender. credentials = _ <br/> new system. net. networkcredential (mailaddressfrom, mailpassword) 'user credential </P> <p>' send an email <br/> mailsender. send (mailmsg) </P> <p> MessageBox. show ("sent successfully. ") </P> <p> catch ex as exception </P> <p> msgbox (" error: "& vbcrlf & Ex. message) </P> <p> end try </P> <p> end sub <br/>

 

===

 

If the above content is useful to you, please reply to any point. Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.