我想要一个vb.net代码,使用vb.net web应用程序发送邮件 [英] i want a vb.net code for send a mail by using vb.net web application

查看:64
本文介绍了我想要一个vb.net代码,使用vb.net web应用程序发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请发送vb.net代码,使用vb.net web应用程序向其他人发送电子邮件

解决方案

修改以下代码并在您的Web应用程序中实施。 。





 受保护  Sub  SendEmail(发件人作为 对象,e 作为 EventArgs)
使用 mm 作为 MailMessage(txtEmail.Text,txtTo.Text)
mm.Subject = txtSubject.Text
mm.Body = txtBody.Text
如果 fuAttachment.HasFile 那么
Dim FileName 作为 字符串 = Path.GetFileName(fuAttach) ment.PostedFile.FileName)
mm.Attachments.Add( New Attachment(fuAttachment.PostedFile.InputStream,FileName))
结束 如果
mm.IsBodyHtml = False
Dim smtp 作为 SmtpClient ()
smtp.Host = smtp.gmail.com
smtp .EnableSsl = True
Dim NetworkCred As NetworkCredential(txtEmail.Text,txtPassword.Text)
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 587
smtp.Send(mm)
ClientScript.RegisterStartupScript( Me GetType alert alert('Email sent。'); True
结束 使用
结束


please send vb.net code for send a email to others by using vb.net web application

解决方案

Modify the below code and implement in your web application..


Protected Sub SendEmail(sender As Object, e As EventArgs)
    Using mm As New MailMessage(txtEmail.Text, txtTo.Text)
        mm.Subject = txtSubject.Text
        mm.Body = txtBody.Text
        If fuAttachment.HasFile Then
            Dim FileName As String = Path.GetFileName(fuAttachment.PostedFile.FileName)
            mm.Attachments.Add(New Attachment(fuAttachment.PostedFile.InputStream, FileName))
        End If
        mm.IsBodyHtml = False
        Dim smtp As New SmtpClient()
        smtp.Host = "smtp.gmail.com"
        smtp.EnableSsl = True
        Dim NetworkCred As New NetworkCredential(txtEmail.Text, txtPassword.Text)
        smtp.UseDefaultCredentials = True
        smtp.Credentials = NetworkCred
        smtp.Port = 587
        smtp.Send(mm)
        ClientScript.RegisterStartupScript(Me.GetType, "alert", "alert('Email sent.');", True)
    End Using
End Sub


这篇关于我想要一个vb.net代码,使用vb.net web应用程序发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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