[Original] how to send emails with image resources

Source: Internet
Author: User
Batch in the backgroundProgramTo send an email with an image, try the attachment method, and find that it is not ideal, it is easy to cause security risks.
This is also not detailed on msdn and the network. Here I will give a detailed introduction to this method. Please refer to the following function. You can modify it to suit your own program:
Private   Sub sendremindmail () Sub Sendremindmail ( Byval Strto As   String , Byval Strtoname As   String , Byval Blnsendtolnemgr As   Boolean )
Dim Objmailmessage As   New Mailmessage
Dim Objsmtpclient As   New Smtpclient
Dim Objaltview As Alternateview
Dim Objlnksrc As Invalid Resource
Dim Sb As   New Stringbuilder

Dim Strfrom, strfromname As   String

Strfrom = Configurationmanager. receivettings ( " Sender " ) ' Read the configuration information in the app. config file.
Strfromname = Configurationmanager. receivettings ( " Sendername " )
Strto =   " LazzyTiger@Sohu.com "
Strtoname =   " Lazzy Tiger "

Objmailmessage. From =   New Mailaddress (strfrom, strfromname)
Objmailmessage. to. Add ( New Mailaddress (strto, strtoname ))
Objmailmessage. Subject =   " Birthday Greeting "

If Blnsendtolnemgr =   True   Then
SB. append ( " <P style = 'font-size: 10pt; font-family: century Gothic, Arial; '> " )
SB. append ( " Please note that your staff listed below does not have email access. kindly ensure that a printed copy of this e-birthday card (preferably in color) reaches your staff within a week's time. " )
SB. append ( " <Br> & nbsp;-& nbsp; "   & Strstaffname &   " & Nbsp ;( "   & Strstaffdeptdescr &   " ) </P> " )
End   If

SB. append ( " <P style = 'font-size: 10pt; font-family: century Gothic, Arial; '> dear colleague, </P> " )
SB. append ( " <P style = 'font-size: 10pt; font-family: century Gothic, Arial; '> </P> " )
SB. append ( " <P style = 'font-size: 10pt; font-family: century Gothic, Arial; '> Best wishes, <br> " )
SB. append ( " Your SingTel family </P> " )

Objaltview = alternateview. createalternateviewfromstring (sb. tostring, encoding. ASCII, "text/html ")
Objlnksrc = new temporary resource (application. startuppath & "/birthday.jpg", "image/jpg ")
Objlnksrc. contentid = "image01"
Objaltview. shareresources. Add (objlnksrc)
Objmailmessage. alternateviews. Add (objaltview)

Objsmtpclient. Host = Configurationmanager. receivettings ( " Smtpserver " )
Objsmtpclient. Send (objmailmessage)
End sub

Note the blue partCodeHere is the key. Of course, you can also connect to the resource files embedded in the program. It's not hard for you to find out.

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.