开发者

SmtpMail - Change the "From Address" to Name

I use SmtpMail for users to forward site content. The user fills out a form which includes first name and email.

The email sent has the full email address as the "From address" in the recipients开发者_开发技巧 inbox (they see From: Joe@Gmail.com while I want them to see From: Joe).

How can I format the "From address" to be the users inputted first name?

Thanks!


The MailAddress class has an optional parameter where you can specify a display name. I assume it will be used when present.

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)


This has always worked for me:

    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)


The format I ended up using was: mailer.From = name & "<" & emailer & ">"

This formats the from address to include Name as well as Email address. It will be displayed in most email clients as Joe <Joe@email.com>. This was my desired outcome.

Thank you Knslyr and lincolnk for the support.


this method displays 'Rameez' instead of '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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜