我想在电子邮件中显示用户名。我已成功发送邮件到邮件ID,现在我想要邮件ID,我也想显示用户名。
这是我的代码,请尽快帮助我。
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]
答案 0 :(得分:1)
您可以使用mail.From地址中的相同逻辑。
mail.To.Add(new MailAddress(EmailTo, ToName));
答案 1 :(得分:0)
试试这个(我知道它是C#,但我希望你能翻译成VB.NET):
mail.To.Add(new MailAddress(EmailTo, EmailToName));
答案 2 :(得分:0)
您使用的是ASp.NET会员吗?如果是这样,你可以尝试这个
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
}