开发者

Display User's Name in email

开发者 https://www.devze.com 2023-03-27 05:35 出处:网络
I want to display the User\'s name in email. I have successfully sent an email to a mail id and now i want along with mail id i want to display user\'s name also.

I want to display the User's name in email. I have successfully sent an email to a mail id and now i want along with mail id i want to display user's name also.

Here is my code please help me a开发者_运维问答s soon as possible.

Public Sub SendMail(ByVal EmailFrom As String, ByVal FromName As String, ByVal ToName As String, ByVal EmailTo As String, ByVal MailSubject As String, ByVal MailBody As String, ByVal Bcc As Int32)
    Try
        Dim mail As New MailMessage()
        Dim smtp As New SmtpClient()
        mail.From = New MailAddress(EmailFrom, FromName)
        mail.To.Add(EmailTo)
        mail.Subject = MailSubject
        mail.Body = MailBody

        mail.IsBodyHtml = True
        smtp.Host = "smtp.gmail.com"   
        smtp.Credentials = New System.Net.NetworkCredential("example@gmail.com","abc")
        smtp.Send(mail)
    Catch ex As Exception
    End Try
End Sub![enter image description here][1]


You can use the same logic from the mail.From address.

mail.To.Add(new MailAddress(EmailTo, ToName));


Try this (I know it's C# but I hope you can translate to VB.NET):

mail.To.Add(new MailAddress(EmailTo, EmailToName));


Are you using ASp.NET Membership?? If so, you can try this

using System.Web.Security;

MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity.Name);

if (user != null)
{
    string username = user.UserName;
    //set your label text here
}
0

精彩评论

暂无评论...
验证码 换一张
取 消