SmtpMail - 将“发件人地址”更改为名称

时间:2010-10-25 20:10:15

标签: vb.net email smtp

我使用SmtpMail为用户转发网站内容。用户填写包含名字和电子邮件的表格。

发送的电子邮件的完整电子邮件地址为收件人收件箱中的“发件人地址”(他们看到来自:Joe@Gmail.com,而我希望他们看到From:Joe)。

如何将“发件人地址”格式化为用户输入的名字?

谢谢!

4 个答案:

答案 0 :(得分:2)

MailAddress类有一个可选参数,您可以在其中指定显示名称。我认为它会在现场使用。

Dim from As MailAddress = New MailAddress("ben@contoso.com", "Ben Miller")
Dim to As MailAddress = New MailAddress("jane@contoso.com", "Jane Clayton")
Dim message As MailMessage = New MailMessage(from, to)

答案 1 :(得分:2)

这一直对我有用:

    Dim myMessage As New MailMessage

    Dim myFrom As MailAddress = New MailAddress("bob@contoso.com", "Bob Denver")
    Dim myTo As MailAddress = New MailAddress("steve@contoso.com", "Steve Miller")

    myMessage.From = myFrom
    myMessage.To.Add(myTo)

答案 2 :(得分:0)

我最终使用的格式为:mailer.From = name & "<" & emailer & ">"

这会将发件人地址格式化为包含姓名和电子邮件地址。它将在大多数电子邮件客户端中显示为Joe <Joe@email.com>。这是我想要的结果。

谢谢Knslyr和lincolnk的支持。

答案 3 :(得分:0)

此方法显示&#39; Rameez&#39;而不是&#39; Rameez@abc.com.pk'

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim objRecip As Recipient
    Dim strMsg As String
    Dim res As Integer
    Dim strBcc As String
    On Error Resume Next

    strBcc = """Rameez"" <Rameez@abc.com.pk>"

    Set objRecip = Item.Recipients.Add(strBcc)
    objRecip.Type = olBCC
        If Not objRecip.Resolve Then
            strMsg = "Could not resolve the Bcc recipient. " & _
            "Do you want still to send the message?"
            res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
            "Could Not Resolve Bcc Recipient")
            If res = vbNo Then
                Cancel = True
            End If
        End If
    Set objRecip = Nothing

    End Sub