Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display name using xp_smtp_sendmail 1

Status
Not open for further replies.

mflancour

MIS
Apr 23, 2002
379
US
Anyone know how to use a display name for the from email when using xp_smtp_sendmail? The problem I'm running into is I have some records that contain somethign like
"name" <email@domain.com>
which apparently worked with whatever was being used previous to xp_smtp_sendmail, but it errors out now, saying invalid email. So, I can either find a way to get it to work or use something like charindex to remove it on the fly.
 
Here is an example I found. Does this help?
Code:
declare @rc int
exec @rc = master.dbo.xp_smtp_sendmail
    @FROM       = N'MyEmail@MyDomain.com',
    @FROM_NAME  = N'Joe Mailman',
    @TO         = N'MyFriend@HisDomain.com',
    @CC         = N'MyOtherFriend@HisDomain.com',

    @BCC        = N'MyEmail@MyDomain.com',

    @priority   = N'HIGH',
    @subject    = N'Hello SQL Server SMTP Mail',
    @message    = N'Goodbye MAPI, goodbye Outlook',
    @type       = N'text/plain',
    @attachments= N'c:\attachment1.txt;c:\attachment2.txt',
    @server     = N'mail.mydomain.com'
select RC = @rc

go

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Thank you, this does work but it does not fix my issue

Picture the from, to, etc comming from a table. in this table some records are fine and work great, while others try to specify a "display name" ie:
@FROM = N'"myname" <MyEmail@MyDomain.com>',

The code does not like this and errors out. Now I'm trying to figure out the best way around this. If all else fails I can just update the table and remove the display name from the records that have it, but I'd rather update my code to be able to send a display name with the email.
 
I don't think you can have the dispay name. But you could strip it off like this.

Code:
[COLOR=blue]DECLARE[/color] @myname [COLOR=blue]varchar[/color](400)

[COLOR=blue]SELECT[/color] @myname = [COLOR=red]'myname <MyEmail@MyDomain.com>'[/color]

[COLOR=blue]SELECT[/color] [COLOR=#FF00FF]SUBSTRING[/color](@myname,[COLOR=#FF00FF]CHARINDEX[/color]([COLOR=red]'<'[/color],@myname),LEN(@myname))

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top