本文介绍了从后面的代码发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在单击按钮时发送电子邮件.我有fromaddress和toaddess.
I want to send an email on click of a button. I have fromaddress and toaddess. Is there a away to send the email without password of fromaddress?
推荐答案
Private Sub SendMail(ByVal StrTo As String, ByVal StrFrom As String, ByVal Subject As String, ByVal body As String)
Try
Dim msgMail As New MailMessage
Dim mailclient As New SmtpClient
Dim toadd As New MailAddressCollection
Dim fromAddress As New MailAddress(StrFrom)
If StrTo.Trim = "" Or StrFrom.Trim = "" Then
Response.Write("<script language='javascript'>alert('No Email found')</script>")
Exit Sub
End If
toadd.Add(StrTo)
msgMail.To.Add(toadd.ToString)
msgMail.From = fromAddress
msgMail.Subject = Subject
msgMail.Body = Server.HtmlDecode(body)
msgMail.IsBodyHtml = True
Dim contentId As String = "imgBand" 'This content id is used in HTML with prefix "cid:"
Dim path As String = Server.MapPath("~") & "\"
Dim filename As String = path & "Images/imageFunction5.png"
Dim av1 As AlternateView
'To create alternate view for Email
'Images can be embedded using alternate view
av1 = AlternateView.CreateAlternateViewFromString(body, Nothing, MediaTypeNames.Text.Html)
'Linking the Band(Image) with the Email content
Dim linkedResource As LinkedResource = New LinkedResource(filename)
linkedResource.ContentId = contentId
linkedResource.ContentType.Name = filename
av1.LinkedResources.Add(linkedResource)
filename = path & "Images/Test logo.gif"
contentId = "imgLogo"
'Linking the Logo (Image)with the Email content
Dim linkedResource_img As LinkedResource = New LinkedResource(filename)
linkedResource_img.ContentId = contentId
linkedResource_img.ContentType.Name = filename
av1.LinkedResources.Add(linkedResource_img)
msgMail.AlternateViews.Add(av1)
mailclient.Host = '"mailhost-sghq.test.net" '"172.1.2.2"
mailclient.Send(msgMail)
Exit Sub
End If
这篇关于从后面的代码发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!