Script to change "from" field when it is empty / blank

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
miguel.cardenas
New user
New user
Posts: 3
Joined: 2014-01-03 16:42

Script to change "from" field when it is empty / blank

Post by miguel.cardenas » 2014-01-03 17:18

Hello,

I would like to have some help with the next issue:

I set up hmail server to work with several aplications using amazon AWS as relay, and it was working ok, last week one of my colegues released a new application to send notifications, but it did not work (the rest of apps are still working fine).

After checking the logs I found that messages sent from the new application were being bounced by amazon as the "from" field was empty:

"SENT: MAIL FROM:<>"
"RECEIVED: 501 Invalid MAIL FROM address provided"

I understand that it is normal, and I know that eventhough I enabled blank fields in hmail server it is amazon who is rejecting those messages, however I can not change either amazon or the application settings to change this scenario, so I would need to change the empty "from" field using hmailserver scripts.

I have used scripts to change subject in the past, but I have not been able to do so with empty senders I think there is something wrong with my syntaxis:


Sub OnAcceptMessage(oClient, oMessage)
If oMessage.From = "" Then
oMessage.From = "<noreply@mydomain.com>"
End If
oMessage.save
End Sub


Please help!!!

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Script to change "from" field when it is empty / blank

Post by Bill48105 » 2014-01-03 17:49

You want oMessage.FromAddress instead of oMessage.From because from is the "name" vs address.
Bill
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***

miguel.cardenas
New user
New user
Posts: 3
Joined: 2014-01-03 16:42

Re: Script to change "from" field when it is empty / blank

Post by miguel.cardenas » 2014-01-03 18:35

Hi,

Thanks for your quick response, I changed the code for

_______________

Sub OnAcceptMessage(oClient, oMessage)
If oMessage.FromAddress = "" Then
oMessage.FromAddress = "no reply@mydomain.com"
oMessage.From = "No reply"
End If
oMessage.save
End Sub

____________________

It did change the email address in the "mail from" section, but I think the application is adding a "from" in the header which is also empty.

I am getting the next error message: Empty required header 'From'


Is there a way to define the "from" field in the header using script? something like oHeader.from or similar?

Thanks in advance

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Script to change "from" field when it is empty / blank

Post by Bill48105 » 2014-01-03 21:30

oMessage.From is the from name oMessage.FromAddress is the email address. We'd have to see your headers to know what it doesn't like. Maybe one of the rec'd headers. You might need to adjust a setting or add/remove/change some other header but hard to say without seeing the headers. ;) You can redact IP/addresses if needed
Bill
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***

miguel.cardenas
New user
New user
Posts: 3
Joined: 2014-01-03 16:42

Re: Script to change "from" field when it is empty / blank

Post by miguel.cardenas » 2014-01-03 21:43

Thank you for your answer, it was really helpfull

Using the oMessage.FromAddress field in the script I can enforce the sender ("from") in the header, and I do not have an error message any more.

Thanks again.

Here is the final code in case somebody could need it.

_________________________

Sub OnAcceptMessage(oClient, oMessage)
If oMessage.FromAddress = "" Then
oMessage.FromAddress = "noreply@mydomain.com"
oMessage.From = "noreply@mydomain.com"
oMessage.FromAddress = "noreply@mydomain.com"
End If
oMessage.save
End Sub

__________________________

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Script to change "from" field when it is empty / blank

Post by Bill48105 » 2014-01-03 23:39

Glad you got it sorted. Why do you have fromaddress twice? does that help fix the problem or typo?
Bill
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***

User avatar
mattg
Moderator
Moderator
Posts: 19920
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Script to change "from" field when it is empty / blank

Post by mattg » 2014-01-05 10:19

I think the issue part way through this thread is the space in the email address.
email addresses can't contain a space
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Post Reply