从后面的代码发送电子邮件 [英] send e-mail from code behind

查看:106
本文介绍了从后面的代码发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击按钮时发送电子邮件.我有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?

推荐答案

可能仅适用于本地网络而不适用于Internet,或者我会说我们不能使用
Yahoo或Gmail或没有密码的任何帐户都可以在我们的应用程序中发送电子邮件[安全原因].
Possible only for local Network not for Internet or i will say that we can not use
Yahoo or Gmail or whatever account is there without password to send email in our application[ Security reasons ] .


您需要SMTP服务器详细信息才能发送邮件.

YOu need the SMTP sever details for sending the mail.

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



这篇关于从后面的代码发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆